---
title: "Encapsulation in C#"  
description: "In this blog, I’m trying to explain the concept of encapsulation.  Encapsulationis defined 'as the process of enclosing one or more items within a phy"  
author: "Sumit Kesarwani"  
published: 2013-05-10  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/492/encapsulation-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Encapsulation in C#

In this blog, I’m trying to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of encapsulation.\

Encapsulation is defined 'as the process of enclosing one or more items within a physical or logical package'. Encapsulation, in object [oriented programming](https://www.mindstick.com/forum/162/object-oriented-programming-oop-s) methodology, prevents access to [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) details.

[Abstraction and encapsulation](https://www.mindstick.com/forum/156710/differentiate-between-data-abstraction-and-encapsulation) are related features in object oriented programming. Abstraction allows making [relevant information](https://answers.mindstick.com/qa/105781/how-to-interpret-financial-news-and-filter-relevant-information-for-investing) visible and encapsulation enables a programmer to implement the desired level of abstraction.

**Encapsulation** is implemented by using access specifier. An access specifier defines the scope and visibility of a class member.

##### C# supports the following access specifier:

- Public
- Private
- Protected
- Internal
- Protected internal

##### Public Access Specifier

Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from [outside the class](https://www.mindstick.com/interview/2468/can-you-access-the-private-method-from-outside-the-class).

##### Private Access Specifier

Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class [cannot access](https://www.mindstick.com/forum/33726/inside-onclicklistener-i-cannot-access-a-lot-of-things-how-to-approach) its private members.

##### Protected Access Specifier

[Protected access](https://www.mindstick.com/forum/156707/what-is-the-difference-between-public-private-and-protected-access-modifiers) specifier allows a [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div) to access the member variables and member functions of its [base class](https://www.mindstick.com/blog/116/base-class-initilization). This way it helps in implementing inheritance. We will discuss this in more details in the inheritance chapter.

##### Internal Access Specifier

Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.

##### Protected Internal Access Specifier

The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application. This is also used while implementing inheritance.

---

Original Source: https://www.mindstick.com/blog/492/encapsulation-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
