See an article on using management from msdn.Article, Feel good, original: http://msdn.microsoft.com/zh-cn/library/bb514115.aspx
In the Visual Studio user interface"Remove unused using"Option to removeSource codeUnusedUsingCommands,UsingAlias andExternAlias. You can call this operation in either of the following ways:
Main Menu:"Edit"Point"Intelliisense"And then point"Organization using"And then click"Remove unused using".
Context Menu: Right-clickCodeAny location in the editor, pointing"OrganizationUsing"And then click"Remove unused using".
Note: |
If you run"Remove unused using"May remove some requiredUsingCommand. |
The following example shows how to execute"Remove unused using"The result.
before execution |
after execution |
copy the Code using system; using system. LINQ; using system. collections. generic; using system. text; using system; namespace consoleapplication1 {class program {static void main (string [] ARGs) {console. writeline ("test") ;}} |
copy the Code using system; namespace consoleapplication1 {class program {static void main (string [] ARGs) {console. writeline ("test") ;}} |
In the previous example, onlySystemIt will be used in source code later. OthersUsingCommands (including duplicateSystemUsing command) will be removed.
Remarks
Conditional Preprocessor commands
"Remove unused using"Only unused commands and aliases in the activity block are removed. The following example illustrates this point:
Before Execution |
After execution |
# define debug # If debug using system; using system. collections. generic; using system. LINQ; # else using system. text; # endif namespace consoleapplication1 { class Program { static void main (string [] ARGs) { List mylist = new list {1, 2, 3 }; console. writeline (mylist ); } } } |
# define debug # If debug using system; using system. collections. generic; # else using system. text; # endif namespace consoleapplication1 { class Program { static void main (string [] ARGs) { List mylist = new list {1, 2, 3 }; console. writeline (mylist ); } } } |
In the preceding exampleSystem. TextAnd is not used.System. LINQ. HoweverSystem. TextIt is not in the activity block, so it will only be removedSystem. LINQ.
Note
Only when the comment is between the mark of the instruction or alias,"Remove unused using"To remove the comment. Comments that appear before or after the mark are not affected. The following example illustrates this point:
Before Execution |
After execution |
using system; /* comment before remains */ using/* Comment between removed */system. LINQ; // comment after remains namespace consoleapplication1 { class Program { static void main (string [] ARGs) { Console. writeline ("My example "); } } } |
Using system; /* Comment before remains */ // Comment after remains Namespace consoleapplication1 { Class Program { Static void main (string [] ARGs) { Console. writeline ("My example "); } } } |
In the above example, removeSystem. LINQ. Only comments between command tags are removed.