Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of Using Directives in C# - Alphabetically

One short and simple question, but I can't find a solution:

'Is it possible to sort the using directives alphabetically?'

Thank you in advance!

like image 341
Odrai Avatar asked May 21 '15 12:05

Odrai


People also ask

How do you order using C#?

go to Options, search for USING. Select Advanced. Check box, "Place 'System' directives first when sorting using". Now a click on the right click context menu, Remove and Sort Usings, will order the using statements 'correctly'.

What is using directive in C#?

The using directive allows you to use types defined in a namespace without specifying the fully qualified namespace of that type. In its basic form, the using directive imports all the types from a single namespace, as shown in the following example: C# Copy. using System.

What is global namespace C#?

:: operator (C# reference) The global namespace is the namespace that contains namespaces and types that are not declared inside a named namespace.


2 Answers

Yes, it is. Just right click your directives, select Organize Usings --> Sort Usings

enter image description here

From documentation;

There are two ways to call the operation:

  • Main Menu - On the Edit menu, point to IntelliSense, point to Organize Usings, and then click Sort Usings.

  • Context Menu - Right-click anywhere inside the code editor, point to Organize Usings, and then click Sort Usings.

EDIT: In Visual Studio 2022, the same option called as Remove and Sort Usings which you can also use Ctrl+R, Ctrl+G shortcut for that.

enter image description here

like image 115
Soner Gönül Avatar answered Oct 30 '22 12:10

Soner Gönül


enter image description here

(C#) On Visual Studio 2017 code editor right-click menu, it is now named "Remove and Sort Usings", not nested in any command. And have CTRL+R, CTRL+G shortcut out of the box.

like image 34
Wappenull Avatar answered Oct 30 '22 13:10

Wappenull