HomeCSharpC# Error CS0837 – The first operand of an ‘is’ or ‘as’ operator may not be a lambda expression, anonymous method, or method group.

C# Error CS0837 – The first operand of an ‘is’ or ‘as’ operator may not be a lambda expression, anonymous method, or method group.

C# Error

CS0837 – The first operand of an ‘is’ or ‘as’ operator may not be a lambda expression, anonymous method, or method group.

Reason for the Error & Solution

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 or .

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.

Example

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;
        }
    }
}

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...