Access Modifiers

How is encapsulation done in C#?

Access specifiers/modifiers help implement Encapsulation in C#.

Declared accessibilityMeaning

public

Access is not restricted.

internal

Access is limited to the current assembly.

protected

Access is limited to the containing class or types derived from the containing class.

private

Access is limited to the containing type (class or struct).

protected internal

Access is limited to the current assembly or types derived from the containing class.

private protected

Access is limited to the containing class or types derived from the containing class within the current assembly.

An assembly is a .dll or .exe created by compiling one or more .cs files in a single compilation.

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.

Members ofDefault member accessibilityAllowed 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.

Last updated