更新:2007 年 11 月
错误消息
应输入整型值
在需要整型数据类型的情况中使用了变量。有关更多信息,请参见
示例
当没有转换或者可用的隐式转换导致了不明确的情形时,会出现此错误。下面的示例生成 CS0151。
// CS0151.cs
public class MyClass
{
public static implicit operator int (MyClass aa)
{
return 0;
}
public static implicit operator long (MyClass aa)
{
return 0;
}
public static void Main()
{
MyClass a = new MyClass();
// Compiler cannot choose between int and long
switch (a) // CS0151
// try the following line instead
// switch ((int)a)
{
case 1:
break;
}
}
} | |
在 Visual Studio 2008 及更高版本中,
class C
{
static void Main()
{
switch (M()) // CS0151
{
default:
break;
}
}
static void M()
{
}
} | |