Rediger

Del via


Access modifiers (C# reference)

Use access modifiers to specify the declared accessibility of a member or a type. This section introduces the four access modifiers:

  • public
  • protected
  • internal
  • private

By using these access modifiers, you can specify the following six accessibility levels:

  • public: No access restrictions.
  • protected: Access is limited to the containing class or types derived from the containing class.
  • internal: Access is limited to the current assembly.
  • protected internal: Access is limited to the current assembly or types derived from the containing class.
  • private: Access is limited to the containing type.
  • private protected: Access is limited to the containing class or types derived from the containing class within the current assembly.

The C# language reference documents the most recently released version of the C# language. It also contains initial documentation for features in public previews for the upcoming language release.

The documentation identifies any feature first introduced in the last three versions of the language or in current public previews.

Tip

To find when a feature was first introduced in C#, consult the article on the C# language version history.

In addition, a top-level (non-nested) type can use the file modifier. The declared type is only visible in the current source file. File scoped types are generally used for source generators. You can't combine the file modifier with any access modifier.

This section also introduces the following concepts:

See also