更新:2007 年 11 月
错误消息
参数修饰符“ref”不能与“this”一起使用。
在 this 关键字修饰静态方法的第一个参数时,它向编译器指示该方法是扩展方法。不需要或不允许对扩展方法的第一个参数使用任何其他修饰符。
示例
下面的示例生成 CS1101:
// cs1101.cs
// Compile with: /target:library
public static class Extensions
{
// No type parameters.
public static void Test(ref this int i) {} // CS1101
// Single type parameter.
public static void Test<T>(ref this T t) {}// CS1101
// Multiple type parameters.
public static void Test<T,U,V>(ref this U u) {}// CS1101
}