Edit

Share via


Compiler Error CS1113

Extension methods 'name' defined on value type 'name' cannot be used to create delegates.

Extension methods that are defined for class types can be used to create delegates. Extension methods that are defined for value types cannot.

To correct this error

  1. Associate the extension method with a class type.

  2. Make the method a regular method on the struct.

Example

The following example generates CS1113:

// cs1113.cs  
using System;  
public static class Extensions  
{  
    public static S ExtMethod(this S s)  
    {  
        return s;  
    }  
}  
  
public struct S  
{  
}  
  
public class Test  
{  
    static int Main()  
    {  
        Func<S> f = new S().ExtMethod; // CS1113  
        return 1;  
    }  
}  

See also