Visual studio and .NET tip 11:- Shortcut way to create Set and Get properties

By Shivprasad Koirala

In big project you have 100’s of classes and each of those classes can have lots of properties.

Visual studio and .NET tip 11:- Shortcut way to create Set and Get properties :-

In big project you have 100’s of classes and each of those classes can have lots of properties. It’s a tedious job to go a declare a private variable and then create set and get properties for them, like the one code snippet shown below.

class Customer
    {
         private string _CustomerName;
        public string CustomerName
        {
            set
            {
                _CustomerName = value;
            }
            get
            {
                 return _CustomerName;
            }
        }

    }

Good news is we have some readymade code snippets in visual studio which can give you an initial shell to start with. So just type “prop” and you should get an intellisense as shown below. Select “propfull” and hit TAB.



Once you hit TAB, you would get a template shell as shown below, now go ahead and give proper data types and property names.
private int myVar;

public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}

Video for above tip and trick:-http://youtu.be/lygcxjWjm1I

Visual studio and .NET tip 11:- Shortcut way to create Set and Get properties  (1864 Views)