Search code examples
c#visual-studiopropertiesgetter-setter

Easy way to generate Getters and Setters in Visual Studio


Is there a way to generate getters and setters in Visual Studio? I'm trying with Alt + R, F and i get this:

public String Denomination
{
    get { return denomination; }
    set { denomination = value; }
}

and what I want is this:

public String getDenomination()
{
    return Denomination;
}

public void setDenomination(String Denomination)
{
    this.Denomination = Denomination;
}

is there a way to do that?


Solution

  • You can use the prop code snippet to create automatic properties.

    Type prop, and press Tab. You can then change the Type and name of the property.

    In your simple case, where no additional logic is required, there's no needed for backing fields.