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

Declare Properties with Initializers (C#)

Adds auto-implemented properties for all parameters of the current constructor and initializes them. Creates linked identifiers for the generated properties references, and drops a marker onto the initial method 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 a constructor name within its declaration, provided that the constructor contains parameters. In addition, parameters should not be used to initialize any properties.

Example

class ClassA
{
    public ClassA(int a, string b)
    {

    }
}

Result:

class ClassA
{
    public ClassA(int a, string b)
    {
        A = a;
        B = b;
    }
    public int A { get; set; }
    public string B { get; set; }
}