Tag Archive | "Techpalle.com"

when to use properties in C#


Properties are used in C# to access/change private variables data from other classes. Since any private data

is not exposed to the outside world so there is no way of modifying private data. By using Properties u can modify private data also.

  • Ex: Public Class Employee { private int _sal=20000;
  • public int Sal
  • { get {return _sal;} set {_sal=Value;}
  • }}
  • Public Class Manager
  • {
  • Employee objEmp=New Employee();
  • Public Manager()
  • {objEmp.Sal=21000;}
  • }

Posted in C# FAQComments (0)