Back to Devexpress

Remove Redundant Constructor

coderushforroslyn-115564-refactoring-assistance-remove-redundant-constructor.md

latest1.7 KB
Original Source

Remove Redundant Constructor

  • Aug 03, 2020
  • 2 minutes to read

Purpose

Removes an empty constructor, if it has no parameters and there are no other constructors in the class. When the class does not contain a constructor, the default one is created internally. The default constructor instantiates the object and sets member variables to the default values as listed in Default Values Table.

Availability

Available when the cursor is on a constructor declaration, provided that the constructor is empty and does not contain parameters. Also, the class should contain no other constructors.

Usage

  1. Place the caret on an empty constructor declaration.

  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.

  3. Select Remove Redundant Constructor from the menu.

After execution, the Refactoring removes the constructor.

csharp
public class Person {
    private int id;
    public string Name { get; set; }
}
vb
Public Class Person
    Private id As Integer
    Public Property Name() As String
End Class

See Also

Remove Redundant Destructor

Remove Unused Member

Remove Redundant Assignment

Add/Remove Block Delimiters