Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Data Encapsulation Example in C#:- 


 It means binding of data using a single unit, Class provide essential details and non-essential details. show essential details and hide non-essential details is managed by abstraction and associate all information under method block is managed by encapsulation.

We should always create private data members because it should not be accessed directly,it must be defined under the method block to access them.

class Classname
{
      private int a,b,c; 
      void MethodName()
     {
            a=100;
            b=200;
            Functionality;
     }

}

Now we create the Object:-

Classname ref = new Classname();
ref.MethodName();

Example of Data Encapsulation Completely:-

class EncapsulationExample
    {
        private int a, b, c;
        private void DisplayHello()
        {
            a = 100;
            b = 200;
            Console.WriteLine(a + b);
        }
        internal void DisplayHello1()
        {
            DisplayHello();
        }
    }
    class EncapMain
    {
        public static void Main()
        {
            EncapsulationExample obj = new EncapsulationExample();
            obj.DisplayHello1();
            Console.ReadKey();
        }
    }


        

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post