Skip to main content

Declare Fields with Initializers

In This Article

Declares new fields and initializes them with the selected methods’ parameters. Creates linked identifiers for the generated field’s references, and drops a marker onto the initial method reference.

#Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on a constructor declaration, provided that the constructor has parameters.

#Example

public class ClassA
{
    public ClassA(int param1, int param2, string param3)
    {

    }
}
Public Class ClassA
    Public Sub New(ByVal param1 As Integer, ByVal param2 As Integer, ByVal param3 As String)

    End Sub
End Class

Result:

public class ClassA
{
    private int _Param1;
    private int _Param2;
    private string _Param3;
    public ClassA(int param1, int param2, string param3)
    {
        _Param1 = param1;
        _Param2 = param2;
        _Param3 = param3;
    }
}
Public Class ClassA
    Private _param1 As Integer
    Private _param2 As Integer
    Private _param3 As String
    Public Sub New(ByVal param1 As Integer, ByVal param2 As Integer, ByVal param3 As String)
        _param1 = param1
        _param2 = param2
        _param3 = param3

    End Sub
End Class