469,344 Members | 6,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,344 developers. It's quick & easy.

VB default class access modifier

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.
Jul 21 '05 #1
2 3285
Which version of the VB compiler are you using? I'm getting private by
default. Also, where is this documentation?

Thanks,
-mike
MVP

"Dan Disney" <dj*@ridgenet.net> wrote in message
news:75****************************@phx.gbl...
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.

Jul 21 '05 #2
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Gerben van Loon | last post: by
1 post views Thread by Jacob N. Rohde | last post: by
5 posts views Thread by Harold Hsu | last post: by
2 posts views Thread by Dan Disney | last post: by
11 posts views Thread by prefersgolfing | last post: by
6 posts views Thread by Tony Johansson | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.