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#

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s