Share via


Compiler Error CS1101

The parameter modifier 'ref' cannot be used with 'this'.

When the this keyword modifies the first parameter of a static method, it signals to the compiler that the method is an extension method. No other modifiers are needed or allowed on the first parameter of an extension method.

Example

The following example generates 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
}

See Also

Reference

Extension Methods (C# Programming Guide)

this (C# Reference)

ref (C# Reference)