【问题标题】:System.Environment and System.Threading.Thread - Using directive is unneccesarySystem.Environment 和 System.Threading.Thread - 不需要使用指令
【发布时间】:2015-08-14 10:05:18
【问题描述】:

我在这两个上收到“使用指令是不必要的”错误。使用它们的正确方法是什么?

【问题讨论】:

  • 错误对我来说很清楚:using namespace 指令只能应用于命名空间;Environment 是一种类型而不是命名空间”。你希望这条线做什么?

标签: c# namespaces using-statement


【解决方案1】:

您可以删除它们,因为 Thread 和 Environment 不是命名空间,而是类型,如您收到的警告中所述

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

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

阅读微软的解释以获得更多信息;

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

【讨论】:

    【解决方案2】:

    你可以像你一样使用 using,你可以给它们命名,比如

    using Thread = System.Threading.Thread;

    using Excel = Microsoft.Office.Interop.Excel;

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

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2021-06-24
      • 2018-02-10
      相关资源
      最近更新 更多