Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A value of an integral type expected
A variable was used in a situation where an integral data type was required. For more information, see Types.
This error can occur when there is no conversion or if the available implicit conversions result in an ambiguous situation. The following example generates CS0151:
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;
}
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: