'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!



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

Yes it is. Context Menu - Right-click anywhere inside the code editor, point to Organize Usings, and then click Sort Usings. https://msdn.microsoft.com/en-us/library/bb514113.aspx

Solution 4:[4]

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'.

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Wappenull
Solution 3 Thomas
Solution 4 RichieMN