# Access Modifiers

#### How is encapsulation done in C#?

Access specifiers/modifiers help implement Encapsulation in C#.

<table><thead><tr><th width="229">Declared accessibility</th><th>Meaning</th></tr></thead><tbody><tr><td><code>public</code></td><td>Access is not restricted.</td></tr><tr><td><code>internal</code></td><td>Access is limited to the current assembly.</td></tr><tr><td><code>protected</code></td><td>Access is limited to the containing class or types derived from the containing class.</td></tr><tr><td><code>private</code></td><td>Access is limited to the containing type (<code>class</code> or <code>struct</code>).</td></tr><tr><td><code>protected internal</code></td><td>Access is limited to the current assembly or types derived from the containing class.</td></tr><tr><td><code>private protected</code></td><td>Access is limited to the containing class or types derived from the containing class within the current assembly.</td></tr></tbody></table>

{% hint style="info" %}
An assembly is a *`.dll`* or *`.exe`* created by compiling one or more *`.cs`* files in a single compilation.
{% endhint %}

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

<table><thead><tr><th width="145.33333333333331">Members of</th><th width="255">Default member accessibility</th><th>Allowed declared accessibility of the member</th></tr></thead><tbody><tr><td><code>enum</code></td><td><code>public</code></td><td>None</td></tr><tr><td><code>class</code></td><td><code>private</code></td><td><code>public</code><br><code>protected</code><br><code>internal</code><br><code>private</code><br><code>protected internal</code><br><code>private protected</code></td></tr><tr><td><code>interface</code></td><td><code>public</code></td><td><code>public</code><br><code>protected</code><br><code>internal</code><br><code>private</code><strong>*</strong><br><code>protected internal</code><br><code>private protected</code></td></tr><tr><td><code>struct</code></td><td><code>private</code></td><td><code>public</code><br><code>internal</code><br><code>private</code></td></tr></tbody></table>

{% hint style="warning" %}
**\*** An `interface` member with `private` accessibility must have a default implementation.
{% endhint %}
