Compiler Error CS0837
The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group.
Lambda expressions, anonymous methods and method groups may not be used on the left side of is or as.
If the error involves the
is
operator, remember thatis
takes a value and a type and tells you whether the value can be made into that type by a reference, boxing, or unboxing conversion. Because lambdas are not values and have no reference, boxing, or unboxing conversions, lambdas are not candidates foris
.If the code misuses
as
, the correction is probably to change it to a cast.
The following example generates CS0837:
// cs0837.cs
namespace TestNamespace
{
public delegate void Del();
class Test
{
static int Main()
{
bool b1 = (() => { }) is Del; // CS0837
bool b2 = delegate() { } is Del;// CS0837
Del d1 = () => { } as Del; // CS0837
Del d2 = delegate() { } as Del; // CS0837
return 1;
}
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: