Move a type to a matching file refactoring

This refactoring applies to:

  • C#

  • Visual Basic

What: Lets you move the selected type to a separate file with the same name.

When: You have multiple classes, structs, interfaces, etc. in the same file which you want to separate.

Why: Placing multiple types in the same file can make it difficult to find these types. By moving types to files with the same name, code becomes more readable and easier to navigate.

How-to

  1. Place the cursor inside the name of the type where it is defined. For example:

    class Person
    
  2. Next, do one of the following:

    • Press Ctrl+.
    • Right-click on the type name and select Quick Actions and Refactorings
  3. Select Move type to TypeName.cs from the menu, where TypeName is the name of the type you've selected.

    The type is moved to a new file in the project that has the same name as the type.

    • C#:

      Inline result - C#

    • Visual Basic:

      Inline result - Visual Basic

See also