The requested page is not available for the requested platform. You are viewing the content for Default platform.

Declare Property (auto-implemented) (C#)

Declares an auto-implemented property for the current reference to an undeclared element. Places the cursor on the generated property declaration and drops a marker onto the initial property reference.

Note

The code provider is only available for .NET framework 3.5 or higher.

Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on an undeclared element reference.

Notes

  • If the code provider is called for an element contained in the right part of an expression, the generated property will contain a private setter. Otherwise, the setter will be public.

Example

private int TestMethod()
{
    return MyProp + 15;
}

Result:

public int MyProp { get; private set; }
private int TestMethod()
{
    return MyProp + 15;
}