Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0428 

Error Message

Cannot convert method group 'Identifier' to non-delegate type 'type'. Did you intend to invoke the method?

This error occurs when converting a method group to a non-delegate type, or attempting to invoke a method without using parentheses.

Example

The following sample generates CS0428:

// CS0428.cs

delegate object Del1();
delegate int Del2();

public class C
{
    public static C Method() { return null; }
    public int Foo() { return 1; }

    public static void Main()
    {
        C c = Method; // CS0428, C is not a delegate type.
        int i = (new C()).Foo; // CS0428, int is not a delegate type.

        Del1 d1 = Method; // OK, assign to the delegate type.
        Del2 d2 = (new C()).Foo; // OK, assign to the delegate type.
        // or you might mean to invoke method
        // C c = Method();
        // int i = (new C()).Foo();
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft