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!
Yes, it is. Just right click your directives, select Organize Usings --> Sort Usings
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.
using
.
Commented
May 21, 2015 at 12:55
development environment
when you installing your Visual Studio, this option might be invisible. Maybe that's why these documents are under the Visual C# IntelliSense page not Visual Basic-Specific IntelliSense
or JavaScript IntelliSense
pages.
Commented
May 21, 2015 at 13:23
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'.
(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.
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
"Order of Using Directives in C# - Alphabetically"
) then the first result (that is't this SO post) tells you the answer. Without looking I would assume the other results point to similar answers. Next time, when you ask a question like this, try saying "I can't be bothered to look properly" or "I can find the answer, but I want to increase my SO question count and maybe get some rep"