Skip to main content

Sort Namespace References

  • 2 minutes to read

Purpose

Sorts namespace references in the “using” (C#) or “Imports” (Visual Basic) section alphabetically or by length.

Availability

Available when the cursor is in a using (Imports) statement if the namespace references are not sorted.

Usage

  1. Open the Editor | All Languages | Namespace References options page to configure this code formatter. For example, set the “Sort namespace references” option to “Alphabetically”.

    SortByName

    For more information about Sort Namespace References options, refer to the following topic: Namespace References Settings.

  2. Place the caret in a using (Imports) statement.

    Note

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

    using System;
    using System.IO;
    using System.Text;
    using System.IO.Compression;
    using System.Collections.Generic;
    using Mono.Cecil.PE;
    using Mono.Cecil.Cil;
    using Mono.Cecil.Metadata;
    using Mono.Collections.Generic;
    using System.UInt32;
    
  3. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  4. Select Sort Namespace References from the menu.

    Choose

After execution, the Code Formatter sorts the namespace references alphabetically.

using Mono.Cecil.Cil;
using Mono.Cecil.Metadata;
using Mono.Cecil.PE;
using Mono.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.UInt32;

Note

This feature is available as a part of Code Cleanup.

See Also