Remove unused using

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.