---
description: C# Access Modifiers are keywords used to define the visibility of a class. Access modifiers restrict other programs to access properties of a class.
title: Access Modifiers (Specifiers) in C# with Program Examples
image: https://www.guru99.com/images/access-modifiers-specifiers-in-c-sharp.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Access modifiers in C# are keywords that set the visibility of a class, property, or method, restricting which external programs can reach them. Constructors initialize field values automatically whenever an object of the class is created.

* 🔐 **Private:** The private access modifier limits a member to the same class, blocking access from any external program.
* 🌐 **Public:** The public access modifier exposes a property or method to any external program without restriction.
* 🛡️ **Protected:** The protected access modifier shares members only with classes inherited from the current class.
* 📦 **Internal:** The internal access modifier permits access within the same assembly but not from an external program.
* 🏗️ **Constructor:** A constructor shares the class name, takes no return type, and initializes fields when an object is created.
* 🤖 **AI assistance:** GitHub Copilot scaffolds modifiers and constructors, while ML.NET maps class properties to model features.

[ Read More ](javascript:void%280%29;) 

![Access Modifiers \(Specifiers\) in C#]()

## What is Access Modifier (Specifier) in C#?

**Access Modifiers** or Access Specifiers in C# are the keywords used to define the visibility of a class property or method. It is used when you do not want other programs to see the properties or methods of a class. Access modifiers restrict access so that other programs cannot see the properties or methods of a class.

There are 6 types of access modifiers in C#:

* Private
* Public
* Protected
* Internal
* Protected Internal
* Private Protected

We will learn about the main access modifiers in C# with program examples as explained below.

## Private Access Modifiers in C#

When Private access modifier is attached to either a property or a method, it means that those members cannot be accessed from any external program.

### Example of Private Access Modifier

Let’s take an example and see what happens when we use the private access modifier.

Let’s modify the current code in our Tutorial.cs file. In the SetTutorial method, let’s change the public keyword to private.

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb10.png)

Now let’s switchover to our Program.cs file. You will notice that there is a red squiggly line under the SetTutorial method.

Since we have now declared the SetTutorial method as private in our Tutorial class, Visual Studio has detected this. It has told the user by highlighting it that now this method will not work from the Program.cs file.

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb11.png)

## C# Public Access Modifiers

When Public access modifier is attached to either a property or a method, it means that those members can be accessed from any external program. We have already seen this in our earlier examples.

### Example of Public Access Modifier

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb12.png)

Since we have defined our methods as public in the Tutorial class, they can be accessed from the Program.cs file.

### RELATED ARTICLES

* [C# Collections Tutorial with Examples ](https://www.guru99.com/c-sharp-collections.html "C# Collections Tutorial with Examples")
* [C# Windows Forms Application Tutorial with Example ](https://www.guru99.com/c-sharp-windows-forms-application.html "C# Windows Forms Application Tutorial with Example")
* [Data Types in C#: Double, Integer, Float, Char ](https://www.guru99.com/c-sharp-data-types.html "Data Types in C#: Double, Integer, Float, Char")
* [C# Hashtable with Examples ](https://www.guru99.com/c-sharp-hashtable.html "C# Hashtable with Examples")

## Protected Access Modifiers in C#

When Protected access modifier is attached to either a property or a method, it means that those members can be accessed only by [classes inherited](https://www.guru99.com/c-sharp-inheritance-polymorphism.html) from the current [class](https://www.guru99.com/c-sharp-class-object.html). This will be explained in more detail in the Inheritance class.

## C# Internal Access Modifiers

When an Internal access modifier is attached to either a property or a method, those members can be accessed only by an internal program but not by an external program.

## C# Constructor

[C#](https://www.guru99.com/c-sharp-tutorial.html) Constructors are used to initializing the values of class fields when their corresponding objects are created. A constructor is a method which has the same name as that of the class. If a constructor is defined in a class, then it will provide the first method which is called when an object is created. Suppose if we had a class called Employee. The constructor method would also be named as Employee().

The following key things need to be noted about constructor methods

1. The C# default access modifier for the constructor needs to be made as public.
2. There should be no return type for the constructor method.

### Example of C# Constructor

Let’s now see how we can incorporate the user of constructors in our code. We will use constructors to initialize the TutorialID and TutorialName fields to some default values when the object is created.

**Step 1)** The first step is to create the constructor for our Tutorial class. In this step, we add the below code to the Tutorial.cs file.

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb13.png)

**Code Explanation:-**

1. We first add a new method which has the same name as that of the class. Because it is the same name as the class, C# treats this as a constructor method. So now whenever the calling method creates an object of this class, this method will be called by default.
2. In the Tutorial constructor, we are setting the value of TutorialID to 0 and TutorialName to “Default”. So whenever an object is created, these fields will always have these default values.

Now let’s switchover to our Program.cs file and just remove the line, which calls the SetTutorial method. This is because we want just to see how the constructor works.

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb14.png)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Tutorial
 {
  public int TutorialID; 
  public string TutorialName;
  
  public Tutorial()
  {
   TutorialID=0;
   TutorialName="Default";
  }
  public void SetTutorial(int pID,string pName) 
  {
   TutorialID=pID;
   TutorialName=pName;
  }
  public String GetTutorial()
  {
   return TutorialName;
  }
  
  static void Main(string[] args) 
  {
   Tutorial pTutor=new Tutorial();
    
   Console.WriteLine(pTutor.GetTutorial());
    
   Console.ReadKey(); 
  }
 }
}

**Code Explanation:-**

1. The first step is to create an object for the Tutorial class. This is done via the ‘new’ keyword.
2. We use the GetTutorial method of the Tutorial class to get the TutorialName. This is then displayed to the console via the Console.WriteLine method.

If the above code is entered properly and the program is executed, the following output will be displayed.

**Output:**

[](https://www.guru99.com/images/c-sharp-net/052616%5F1050%5FCClassandOb15.png)

From the output, we can see that the constructor was indeed called and that the value of the TutorialName was set to “Default”.

**Note:** Here the value “default” is fetched from the constructor.

## FAQs

🔑 What is the default access modifier in C#?

If no modifier is specified, class and struct members default to private and top-level types to internal, staying hidden until you widen their visibility.

🎲 What is the difference between protected and internal in C#?

Protected exposes a member to the same class and any derived class, even across assemblies. Internal exposes it only to types in the same assembly.

🔗 What are protected internal and private protected in C#?

Protected internal allows access from the same assembly or any derived class. Private protected is stricter, allowing only derived classes inside the same assembly.

🏗️ What are the types of constructors in C#?

C# supports default, parameterized, copy, static, and private constructors. They initialize an object’s fields, run class setup once, or clone another object’s values.

⚙️ What is a static constructor in C#?

A static constructor takes no modifier or parameters. It runs once, before the first object is created or static members load, initializing static fields.

🔄 Can constructors be overloaded in C#?

Yes. A class can define several constructors with different parameter lists. The compiler picks the one matching the arguments passed to new.

🤖 Can GitHub Copilot generate C# access modifiers and constructors?

Yes. GitHub Copilot suggests modifiers, constructors, and field initializers from a class name or comment inside Visual Studio and VS Code. Review each suggested visibility level.

🧠 How do access modifiers matter for ML.NET machine learning classes?

ML.NET maps the public properties of a C# data class to model features and labels. Public getters and setters let it read those values during training.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/access-modifiers-specifiers-in-c-sharp.png","url":"https://www.guru99.com/images/access-modifiers-specifiers-in-c-sharp.png","width":"700","height":"250","caption":"Access Modifiers (Specifiers) in C#","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/c","name":"C#"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html","name":"Access Modifiers (Specifiers) in C# with Program Examples"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#webpage","url":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html","name":"Access Modifiers (Specifiers) in C# with Program Examples","dateModified":"2026-07-11T15:11:45+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/access-modifiers-specifiers-in-c-sharp.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/benjamin","name":"Benjamin Walker","description":"I'm Benjamin Walker, an expert in C, C++, and C# programming, providing resources to enhance your coding proficiency and project outcomes.","url":"https://www.guru99.com/author/benjamin","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/benjamin-walker-author.png","url":"https://www.guru99.com/images/benjamin-walker-author.png","caption":"Benjamin Walker","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"C#","headline":"Access Modifiers (Specifiers) in C# with Program Examples","description":"C# Access Modifiers are keywords used to define the visibility of a class. Access modifiers restrict other programs to access properties of a class.","keywords":"c#","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/benjamin","name":"Benjamin Walker"},"dateModified":"2026-07-11T15:11:45+05:30","image":{"@id":"https://www.guru99.com/images/access-modifiers-specifiers-in-c-sharp.png"},"copyrightYear":"2026","name":"Access Modifiers (Specifiers) in C# with Program Examples","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the default access modifier in C#?","acceptedAnswer":{"@type":"Answer","text":"If no modifier is specified, class and struct members default to private and top-level types to internal, staying hidden until you widen their visibility."}},{"@type":"Question","name":"What is the difference between protected and internal in C#?","acceptedAnswer":{"@type":"Answer","text":"Protected exposes a member to the same class and any derived class, even across assemblies. Internal exposes it only to types in the same assembly."}},{"@type":"Question","name":"What are protected internal and private protected in C#?","acceptedAnswer":{"@type":"Answer","text":"Protected internal allows access from the same assembly or any derived class. Private protected is stricter, allowing only derived classes inside the same assembly."}},{"@type":"Question","name":"What are the types of constructors in C#?","acceptedAnswer":{"@type":"Answer","text":"C# supports default, parameterized, copy, static, and private constructors. They initialize an object\u2019s fields, run class setup once, or clone another object\u2019s values."}},{"@type":"Question","name":"What is a static constructor in C#?","acceptedAnswer":{"@type":"Answer","text":"A static constructor takes no modifier or parameters. It runs once, before the first object is created or static members load, initializing static fields."}},{"@type":"Question","name":"Can constructors be overloaded in C#?","acceptedAnswer":{"@type":"Answer","text":"Yes. A class can define several constructors with different parameter lists. The compiler picks the one matching the arguments passed to new."}},{"@type":"Question","name":"Can GitHub Copilot generate C# access modifiers and constructors?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot suggests modifiers, constructors, and field initializers from a class name or comment inside Visual Studio and VS Code. Review each suggested visibility level."}},{"@type":"Question","name":"How do access modifiers matter for ML.NET machine learning classes?","acceptedAnswer":{"@type":"Answer","text":"ML.NET maps the public properties of a C# data class to model features and labels. Public getters and setters let it read those values during training."}}]}],"@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#schema-1141465","isPartOf":{"@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/c-sharp-access-modifiers-constructor.html#webpage"}}]}
```
