C# property

C# class property is set by get, set keywords, and provides convenient way to set and get the property values.

class human
{
public int age;
public string sex;
public human(int a, string s) {age=a;sex=s;}
public string isex
{
get
{
return sex;
}
set
{
sex = value;
}
}
}

To use class property:
human chris = new human(23,"female");
chris.isex; //female
chris.isex = "male"; //chris's sex is now male



endmemo.com © 2017  Terms of Use | Home