This documentation is archived and is not being maintained.

Compiler Error CS0837

Visual Studio 2008

The first operand of an "is" or "as" operator may not be a lambda expression or anonymous method.

Lambda expressions and anonymous methods may not be used on the left side of is or as.

To correct this error

  • If the error involves the is operator, remember that is 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 for is.

  • 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;
        }
    }
}
Show: