What is Encapsulation in C#.Net

  •  
  • Encapsulation is process of hiding complex processing outside the word means you can create cover over data which protect the data from accessing outside word.
  • Encapsulation can be achieved by using keyword like Public, private, Protected…..

Example:

public class Department
{
         private string departname;

         // Accessor.
         public string GetDepartname()
         {
                  return departname;
         }
         // Mutator.
         public void SetDepartname( string a)
         {
                   departname=a;
         }
}
public static int Main(string[] args)
{
         Department d = new Department();
         d.SetDepartname("ELECTRONICS");
         Console.WriteLine("The Department is :"+d.GetDepartname());
          return 0;
}

See Also :
  Follow Me On Facebook
--
/\/ir@\/  <(.'.)>

Comments

Post a Comment

Popular posts from this blog

How to get column value from the selected row in data grid in wpf c#.net

How to make and use web service in Microsoft Dynamics Navision.

How to use Format function in Microsoft Dynamics Navision.