C# Encapsulation - c# - c# tutorial - c# net




What is encapsulation in C# ?

  • Encapsulation is used to hide its members from outside class or interface, whereas abstraction is used to show only essential features.
  • Encapsulation is implemented by using access specifiers.
  • An access specifier defines the scope and visibility of a class member.
  • In C# programming, Encapsulation uses 5 types of modifier to encapsulate data.
 encapsulation
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

C# supports the following access modifiers:

  • Public
  • Private
  • Protected
  • Internal
  • Protected internal

Public

  • In c#, the class member, that is defined as public can be accessed by other class member that is initialized outside the class.
  • A public member can be accessed from anywhere even outside the namespace.

Private

  • The private access specifiers restrict the member variable or function to be called outside from the parent class
  • Private access specifier allows a class to hide its member variables and member functions from other functions and objects.

Protected

  • The protected access specifier hides its member variables and functions from other classes and objects.
  • This type of variable or function can only be accessed in child class. It becomes very important while implementing inheritance.

Internal:

  • Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.
  • The internal access specifier hides its member variables and methods from other classes and objects, that is resides in other namespace.
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

Protected internal

  • The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, but a child class within the same application.
  • Protected internal is also used while implementing inheritance.
learn c# tutorials - encapsulation vs abstaction in c#

learn c# tutorial - encapsulation vs abstaction csharp in c# Example



Related Searches to C# Encapsulation

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×