Alias Varghese Alias Varghese - 20 days ago 5
C# Question

Shortcut to change property to full property

I already have a property like this

public int MyProperty{get; set;}


I need to change this property as a full property like this

private int myVar;

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


any shortcut available in VS2013 for this?

Answer

In VS2015, Right click on myVar -> Quick Actions...-> Encapsulate field

Even better if you first rename it as m_myVar -> Visual studio will generate a property named MyVar

Don't have VS2013 right now, but should be the same, maybe no need for "Quick actions..."