Export (0) Print
Expand All
Expand Minimize

Compiler Error CS1101

Visual Studio 2008

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.

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
}

Community Additions

ADD
Show:
© 2015 Microsoft