VISUAL STUDIO 使用技巧大全 中英文版本之 一 - 命名空间引用管理

本文介绍如何使用Visual Studio的'RemoveUnusedUsings'选项来移除未在源代码中使用的命名空间,从而优化代码。操作可以通过主菜单或上下文菜单进行,确保仅保留实际使用的命名空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://msdn.microsoft.com/en-us/library/bb514115.aspx 

Removing Unused Usings

 

The Remove Unused Usings option in the Visual Studio user interface removes using directives, using aliases, and extern aliases that are not used in the source code. There are two ways to call the operation:

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

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

    Note Note

    If you perform Remove Unused Usings on source code that does not build, some required using directives may be removed.

The following example shows the outcome of performing Remove Unused Usings on source code.

 

Before

After

 
 
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");
        }
    }
}
 
 
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("test");
        }
    }
}

In the previous example, only System is used later in the source code. The other using directives, including the duplicate System using directive, are removed.

 

转载于:https://www.cnblogs.com/taoqianbao/p/3886711.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值