Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error CS1662
Collapse the table of content
Expand the table of content

Compiler Error CS1662

Cannot convert anonymous method block to delegate type 'delegate type' because some of the return types in the block are not implicitly convertible to the delegate return type

This error occurs if the anonymous method block's return statement had a type that was not implicitly convertible to the return type of the delegate.

The following sample generates CS1662:

// CS1662.cs

delegate int MyDelegate(int i);

class C
{

  public static void Main()
  {
     MyDelegate d = delegate(int i) { return 1.0; };  // CS1662
     // Try this instead:
     // MyDelegate d = delegate(int i) { return (int)1.0; };
  }
}

Community Additions

ADD
Show:
© 2015 Microsoft