I'm trying to find a reference for the default visibility of various aspects of C#. Class types, fields, methods, enums, etc.
Can someone provide a list of these along with their default visibility (i.e., no prefixed modifier)?
I'm trying to find a reference for the default visibility of various aspects of C#. Class types, fields, methods, enums, etc.
Can someone provide a list of these along with their default visibility (i.e., no prefixed modifier)?
From MSDN:
Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.
Nested types, which are members of other types, can have declared accessibilities as indicated in the following table.
| Members of | Default member accessibility | Allowed declared accessibility of the member |
|---|---|---|
enum |
public |
None |
class |
private |
publicprotectedinternalprivateprotected internalprivate protected |
interface |
public |
publicprotectedinternalprivate*protected internalprivate protected |
struct |
private |
publicinternalprivate |
* An interface member with private accessibility must have a default implementation.
Source: Accessibility Levels (C# Reference) (September 15th, 2021)