VB default class access modifier

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.
 
M

Michael Giagnocavo [MVP]

Which version of the VB compiler are you using? I'm getting private by
default. Also, where is this documentation?

Thanks,
-mike
MVP
 
M

Mattias Sjögren

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top