Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0151

A value of an integral type expected

A variable was used in a situation where an integral data type was required. This can happen when there is no conversion or if the available implicit conversions result in an ambiguous situation.

The following sample generates CS0151:

// CS0151.cs
public class iii
{
   public static implicit operator int (iii aa)
   {
      return 0;
   }

   public static implicit operator long (iii aa)
   {
      return 0;
   }

   public static void Main()
   {
      iii a = new iii();

      switch (a)   // CS0151, compiler cannot choose between int and long
      // casting is one way to resolve this error
      // switch ((int)a)
      {
         case 1:
            break;
      }
   }
}
Show:
© 2015 Microsoft