VB default class access modifier

  • Thread starter Thread starter Dan Disney
  • Start date Start date
D

Dan Disney

I have read conflicting information on the access scope
of VB.Net class declarations when no access modifier is
specified. MSDN library documentation states "Classes
that do not specify an access modifier are declared as
Friend by default" However, another source, VB.Net Class
Design Handbook by Wrox Press states that no a "no class
access modifier results in an implicit scope of public to
all assemblies". In fact, if I create a class with no
access modifier, compile the example, then view the MSIL
code in the MSIL Disassemble (using ILdasm.exe), I see
that this class is qualified with the MSIL keyword
public; i.e., it has the same scope as a class I declared
as Public. ????? Please straighten this out for me.
 
Which version of the VB compiler are you using? I'm getting private by
default. Also, where is this documentation?

Thanks,
-mike
MVP
 
Dan,

For top-level classes, the default is Friend (which at this level is
effectively the same as Private). For nested classes, the default is
Public.

So the following code

Class Foo
Class Bar
End Class
End Class

compiles to

..class private Foo
{
.class nested public Bar
{
}
}



Mattias
 
Back
Top