Home > View Post

Default access level

In C# the default access level of Form Controls is private:

private System.Windows.Forms.Button button1;

In VB.NET the default access level is Friend (the Modifiers property), which for those of you who have not worked with VB.NET is the C# equivalent of internal.

Friend WithEvents Button1 As System.Windows.Forms.Button

Default access level

Whatever happended to Encapsulation?

Tags: Other

Bruusi Post By Bruusi
1:33 AM
14 Jul 2006

» Next Post: Not everybody has superhuge monitor
« Previous Post: Blowing our own trumpet

Comments are closed for this post.

Posted by R. Aaron Zupancic @ 17 Jul 2006 10:46 AM
Not that I don't disagree (I would MUCH prefer that VB defaulted to private as well), but I think it's there mostly for backwards compatibility and for the folks that are using VB.NET having come from the pre-.NET days. Back then, all controls were public by default (which IMO is even worse as a default).

Developers had the ability to affect any control on any form instance to which they had a handle.

That said, I'm glad that MS opted for a slightly-less-than-optimal approach in choosing Friend over Public. <InTheory>At least that way most code would still port - in principle, that is.</InTheory>. I wish MS would have bitten the bullet a bit harder and simply chosen Private and pushed the onus on the developer to write better code rather than leave it as it is now.

Being that I write almost exclusively in C#, however, it doesn't bug me as much as when I tinkered with VB.NET for a bit.

Posted by Greg Smith @ 25 Feb 2008 9:22 PM
I don't think VB.Net programmers know the meaning of Encapsulation.

© 2005 - 2022 Josh Twist - All Rights Reserved.