Tag Archives: Auto-Implemented Properties

Auto-Implemented Properties

Auto-Implemented Properties

In C# 2.0 properties are declared as follows:

private int iEmpId;
private string strEmpName;

public int EmpId
{
get { return iEmpId; }

set { iEmpId = value; }
}

Samething is redfined in C#3.0 using auto-implemented properties like:
public class AutoProperties
{
public int EmpID { get; set; }
public string EmpName { get; set; }
public int Age { get; private set; } // read-only
}
Behind the scene, compiler automatically creates private, anonymous fields that can be accessed from the above auto-implemented properties.

Leave a comment

Filed under C#