What is the default access modifier for classes, methods, members, constructors, delegates and interfaces?
C# – What are the default access modifiers in C#
access-modifiersc
Related Topic
- Java – the difference between public, protected, package-private and private in Java
- C# – What are the correct version numbers for C#
- C# – Case insensitive ‘Contains(string)’
- C# – In C#, what is the difference between public, private, protected, and having no access modifier
- C# – Internal vs. Private Access Modifiers
- C# – reason for C#’s reuse of the variable in a foreach
Best Answer
The default access for everything in C# is "the most restricted access you could declare for that member".
So for example:
is equivalent to
The one sort of exception to this is making one part of a property (usually the setter) more restricted than the declared accessibility of the property itself:
This is what the C# 3.0 specification has to say (section 3.5.1):
(Note that nested types would come under the "class members" or "struct members" parts - and therefore default to private visibility.)