Quick create C# properties from variables

user204588 picture user204588 · Apr 27, 2010 · Viewed 28.5k times · Source

For C#, I hate writing out the variables and then writing out all the properties. Isn't there a way to select all variables, right click and create all the properties.

Answer

mico picture mico · Apr 27, 2010

Right click on the field declaration, menu Refactor -> Encapsulate field and you go from

int n;

to

int n;

public int N
{
   get { return n; }
   set { n = value; }
}