Wednesday, October 14, 2015

List of Default Access Modifiers of Types and Members for VB.NET and C#

It does not seem as easy as it looks like to sort this out. Though information about this is spread over the web everywhere, inconsistencies, incompleteness, and even errors are here and there. 

It took us quite a while to put together the following list:

                                              VB.NET         C#
Class types (not nested)            Friend/Public    Internal
Class members (including nested types)        Public        Private
Structure types (not nested)            Friend/Public    Internal
Structure members (including nested types)    Public         Private
Interface types (not nested)            Friend/Public    Internal
Interface members (including nested types)    Public        Public
Enum types (not nested)                Friend/Public    Internal
Enum members (including nested types)        Public        Public
Delegate types (not nested)            Friend/Public    Internal
Delegate types (nested)                Public        Private
Delegate members                 N/A        N/A


As can be noticed, the default access modifier has two values for VB.NET. It is because VB.NET has one extra level, Module. The first default is for the VB.NET Namespace level, which also exists in C#, and the second is for the Module level of VB.NET.

If still something missing or inconsistent or incomplete, please feel free to make comments.

 

1 comment: