Compiler Error CS0151
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.
Example of ambiguous conversion
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;
}
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for