Encapsulation in C#

using System;

namespace EncapsulationExample
{
    class Student
    {
        public string ID
        {
            get; set;
        }

        public string Name
        {
            get; set;
        }

        public string Email
        {
            get; set;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //setting values to properties
            Student student1 = new Student();
            student1.ID = "101";
            student1.Name = "Zaki Live";
            student1.Email = "[email protected]";
            Student student2=new Student();

            student2.ID = "233";
            student2.Name = "SS";
            student2.Email = "[email protected]";

            //getting values to properties

            Console.WriteLine("ID="+student1.ID);
            Console.WriteLine("Name="+student1.Name);
            Console.WriteLine("Email="+student1.Email);

            Console.WriteLine("ID=" + student2.ID);
            Console.WriteLine("Name=" + student2.Name);
            Console.WriteLine("Email=" + student2.Email);

            Console.ReadKey();
        }
    }
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.