更新:2007 年 11 月
错误消息
在值类型“name”上定义的扩展方法不能用于创建委托。
为类类型定义的扩展方法可用于创建委托。为值类型定义的扩展方法则不能。
更正此错误
将扩展方法与类类型相关联。
使该方法成为该结构上的常规方法。
示例
下面的示例生成 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;
}
}