【发布时间】:2018-03-28 21:10:52
【问题描述】:
我正在使用来自C#6 的using static 指令来引用枚举的值而不提供其类型名,这对可读性很有帮助。不幸的是,当我在调试期间尝试向 Watch 窗口添加这样的引用时,它给了我一个 CS0103 错误。这是一个例子:
using System.Collections.Generic;
using static ConsoleApplication1.MyEnumType;
namespace ConsoleApplication1
{
public enum MyEnumType
{
thing1,
thing2,
}
class Program
{
static void Main()
{
Dictionary<MyEnumType, int> dict = new Dictionary<MyEnumType, int>();
// add the left-hand side of these expressions to watch window:
dict[MyEnumType.thing1] = 1; //Watch Value = 1
dict[thing2] = 2; //Watch Value = error CS0103: The name 'thing2' does not exist in the current context
}
}
}
由于 using static 指令,最后一行代码编译得很好。但是在调试时,如果我尝试将 dict[thing2] 添加到 Watch 窗口,我会收到错误消息。有没有办法解决这个问题?
更新:这是has been reported 的一个已知错误,但截至今天(我提交错误报告 9 个月后),还没有尝试解决它。当然,解决方法是简单地将类型名称添加到监视窗口(虽然很明显,但当我第一次发布此内容时,我却忽略了)。
【问题讨论】:
-
它看起来确实像您应该在 Connect 上报告的内容(或现在的任何内容)。
标签: c# debugging visual-studio-2017 c#-6.0 using-directives