System.Environment和System.Threading.Thread - 使用指令是不必要的

时间:2015-08-14 10:05:19

标签: c# namespaces using-statement

我在这两个上面得到“Using directive is unneccesary”错误。使用它们的正确方法是什么?

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以删除它们,因为线程和环境不是命名空间,而是类型,也可以在警告中说明

using System.Threading
using System; // which already exists as the first using statement

Using语句用于包含名称空间,其中包含类,类,枚举等类型。例如,通过添加System.Threading,您就可以访问Thread类。

阅读Microsoft的说明以获取更多信息;

https://msdn.microsoft.com/en-us/library/0d941h9d.aspx

答案 1 :(得分:1)

您可以使用类似的用途,您可以将它们命名为

using Thread = System.Threading.Thread;

using Excel = Microsoft.Office.Interop.Excel;

有关信息 https://msdn.microsoft.com/en-us/library/sf0df423.aspx

相关问题