Use of encapsulation - C#.NET

Explain the use of encapsulation.

Encapsulation hides the internal state and behavior of an object. Encapsulation if used with access modifiers such as private, public, protected. It provides a way to protect data.
public class MyClass
{
   private string name;
   public string Name
   {
       get
       {
           return name;
       }
       set
       {
            name = value;
       }
   }
}
public class main
{
    public static int Main(string[] args)
   {
        MyClass myclass = new MyClass();
        myclass.name = "Communication";
       Console.WriteLine("The name is :{0}", myclass.Name);
       return 0;
   }
}
See use of encapsulation through properties for accessing and setting the values.
Differentiate between instance data and class data - C#.NET
Differentiate between instance data and class data - Class data in terms of static class is the data that particular class holds in its structure...
Significance of static method - C#.NET
Explain the significance of static method - Static methods are used when we want only one copy of that method to perform action and remain active at a single point in time...
Uses of boxing and unboxing - C#.NET
Explain the uses of boxing and unboxing - Boxing and Unboxing are used to convert value types into reference types and vice versa...
Post your comment