Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0508

'function1' cannot change return type when overriding inherited member 'function2'

An attempt was made to change the return type in a method override.

The following sample generates CS0508:

// CS0508.cs
namespace x
{
   abstract public class clx
   {
      public int i = 0;
      abstract public int f();   // return type is int
   }

   public class cly : clx
   {
      public override double f()
      {
         return 0.0;             // CS0508
      }

      public static int Main()
      {
         return 0;
      }
   }
}
Show:
© 2014 Microsoft