Skip to main content

Remove Unused Member

Purpose

Used to remove a class member (field, property, method, event, etc.) that is never used.

Availability

Available when the cursor is on the member name (if this member is never assigned or referenced).

Usage

  1. Place the caret on an unused member name.

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    public class Person {
        private int CustomerID;
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Remove Unused Member from the menu.

After execution, the Refactoring removes the member.

public class Person {
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
See Also