Edit

Share 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.

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