C# 3.0 : Automatic Properties

Hello ,

Being a C# programmer , you’ve used to leverage propcode snippet to create a property . C# 3.0 provides you with a nice feature called “Automatic Properties” which enables you to avoid having to declare private accessor field for properties and write get/set logic , this will make your code more concise and legible . However , you can still create regular properties and change get/set logic.

This is a property created by C# 2.0 :

        private string propertyName;
        public string PropertyName
            get { return propertyName; }
            set { age= propertyName; }

And this one is re-writed using C# 3.0 :

public string PropertyName { get; set; }

Implementing this feature , the compiler automatically creates the get/set logics . If you need to make the above property readonly , add private keyword before set accessor :

public string PropertyName { get; private set; }


One Response to C# 3.0 : Automatic Properties

  1. SIR_asad says:

    Good post about programming .

    tnx man

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: