How to use properties in c# classes?
Properties provide a flexible mechanism to read, write, or compute the value of a private field.
Example:
public class Person
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
Solution:
Auto-implemented properties make property-declaration more concise:
public class Person
{
public string Name { get; set; }
}