Compiler Error CS0407
'return-type method' has the wrong return type
The method was not compatible with the delegate type. The argument types matched, but the return type was not the correct return type for that delegate. To avoid this error, use a different method, change the method's return type, or change the delegate's return type.
The following sample generates CS0407:
C#
// CS0407.cs
public delegate int MyDelegate();
class C
{
MyDelegate d;
public C()
{
d = new MyDelegate(F); // OK: F returns int
d = new MyDelegate(G); // CS0407 – G doesn't return int
}
public int F()
{
return 1;
}
public void G()
{
}
public static void Main()
{
C c1 = new C();
}
}
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.
.NET feedback
.NET is an open source project. Select a link to provide feedback: