Skip to main content

Declare Constructor

Adds a constructor to a class. Creates text fields for the constructor parameters and drops a marker onto the initial constructor reference. To choose the constructor declaration position, use the Target Picker.

#Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on a reference to a class constructor, provided that the class does not contain a constructor with the same parameters as the reference.

#Notes

The constructor will have the same parameters as its reference.

#Example

public class ClassA
{
    private string Name;
}
class TestClass
{
    private void TestMethod()
    {
        ClassA objVar = new ClassA("Name");
    }
}
Public Class ClassA
    Private Name As String
End Class
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar = New ClassA("Name")
    End Sub
End Class

Result:

public class ClassA
{
    public ClassA(string param1)
    {
        throw new NotImplementedException();
    }
    private string Name;
}
class TestClass
{
    private void TestMethod()
    {
        ClassA objVar = new ClassA("Name");
    }
}
Public Class ClassA
    Public Sub New(ByVal param1 As String)
        Throw New NotImplementedException()
    End Sub
    Private Name As String
End Class
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar = New ClassA("Name")
    End Sub
End Class