Edit

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. With C# version 7.1 and below, no other modifiers are needed or allowed on the first parameter of an extension method. Since C# version 7.2, ref extension methods are allowed, take a look at extension methods for more details.

Example

The following example generates CS1101:

C#
// cs1101.cs
// Compile with: /target:library
public static class Extensions
{
    public static void Test(ref this int i) {} // CS1101
}

See also