Default visibility for C# classes and members (fields, methods, etc.)?

Viewed 130573

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)?

4 Answers

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 public
protected
internal
private
protected internal
private protected
interface public public
protected
internal
private*
protected internal
private protected
struct private public
internal
private

* An interface member with private accessibility must have a default implementation.

Source: Accessibility Levels (C# Reference) (September 15th, 2021)

Related