---
title: "Explain different accessibility modifiers and how many are there in C# with examples."  
description: "Explain different accessibility modifiers and how many are there in C# with examples."  
author: "Revati S Misra"  
published: 2023-04-14  
updated: 2023-04-24  
canonical: https://www.mindstick.com/forum/157795/explain-different-accessibility-modifiers-and-how-many-are-there-in-c-sharp-with-examples  
category: "oops"  
tags: ["c#", "oops"]  
reading_time: 3 minutes  

---

# Explain different accessibility modifiers and how many are there in C# with examples.

[Explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) different [accessibility](https://www.mindstick.com/blog/304975/why-image-alt-text-matters-for-seo-and-accessibility) modifiers and how many are there in C# with examples.

## Replies

### Reply by Aryan Kumar

In C#, there are five accessibility modifiers: public, private, protected, internal, and protected internal. These modifiers control the level of access that a class, method, property, or field has to other classes or code within the same assembly or outside of it.

**Public:** A public member is accessible from any code within the assembly or outside of it. This modifier is commonly used for methods, properties, and fields that need to be accessed by other code.

```cs
Example:
public class MyClass {
  public int MyProperty { get; set; }
  public void MyMethod() {
     // do something
  }
}
```

**Private:** A private member is only accessible from within the same class or struct. This modifier is used to encapsulate implementation details and hide them from other code.

Example:

```cs
public class MyClass {
  private int myField;
  private void MyMethod() {
     // do something
  }
}
```

**Protected:** A protected member is accessible from within the same class or struct, as well as any derived class. This modifier is used to expose implementation details to derived classes while still encapsulating them from other code.

Example:

```cs
public class MyBaseClass {
  protected int myField;
  protected void MyMethod() {
     // do something
  }
}
public class MyDerivedClass : MyBaseClass {
  public void AnotherMethod() {
     myField = 10; // can access the protected field from the base class
     MyMethod(); // can call the protected method from the base class
  }
}
```

**Internal:** An internal member is accessible from any code within the same assembly, but not from code outside of it. This modifier is used to expose implementation details to other code within the same assembly.

Example:

```cs
internal class MyClass {
  internal int MyField;
  internal void MyMethod() {
     // do something
  }
}
```

**Protected internal:** A protected internal member is accessible from within the same assembly, as well as any derived class whether inside or outside of the assembly. This modifier is used to expose implementation details to derived classes within the same assembly, as well as to other code within the same assembly.

Example:

```cs
public class MyBaseClass {
  protected internal int myField;
  protected internal void MyMethod() {
     // do something
  }
}
public class MyDerivedClass : MyBaseClass {
  public void AnotherMethod() {
     myField = 10; // can access the protected internal field from the base class
     MyMethod(); // can call the protected internal method from the base class
  }
}
```


---

Original Source: https://www.mindstick.com/forum/157795/explain-different-accessibility-modifiers-and-how-many-are-there-in-c-sharp-with-examples

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
