【问题标题】:How to use using directive with static type如何使用静态类型的 using 指令
【发布时间】:2016-07-02 01:58:24
【问题描述】:

在 MSDN here 的示例中,它解释了如何将 using 指令与静态类型一起使用。

但是,当我尝试使用以下代码模仿示例时,出现错误。

我做错了什么?

namespace ConsoleApplication1
{
    // intellisense syntax errors show up in this line
    using static System.Console;

    class Program
    {
        static void Main(string[] args)
        {
            // do something
        }
    }
}

【问题讨论】:

  • 什么版本的 Visual Studio/编译器?
  • @DanielA.White 我想我明白你的意思了。
  • 它在 .net 4.5 vs2015 上非常适合我
  • using 声明应该在 namespace 声明之外
  • @mrtig:不,在任何地方都可以。 (这是一个 using directive,顺便说一句。一个 using statement 是您用于资源的,用于自动处理它们。)

标签: c# c#-5.0


【解决方案1】:

这在 Visual Studio 2013 或 C# 5.0 中不受支持。这是 C# 6.0 的一项功能。

【讨论】:

  • 是的,就是这样。得看我的版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
  • 2016-10-01
  • 1970-01-01
相关资源
最近更新 更多