rksoftware

Visual Studio とか C# とかが好きです

public static void Method(this ref string s)

拡張メソッドの引数に ref 参照型

public static void Method(this ref string s)

ってできないんですね。値型ならできますけれど。

Console.WriteLine();

static class Class
{
    public static int Method(this object o) => 0;
    public static int MethodRef(this ref object o) => 0;
    public static int Method(this int i) => 0;
    public static int MethodRef(this ref int i) => i=1;
    public static int Method(this string s) => 0;
    public static int MethodRef(this ref string s) => 0;
}
ref' 拡張メソッド 'MethodRef' の最初のパラメーターは、値型または構造体に制限されたジェネリック型でなければなりません。

そもそも拡張メソッドの引数に ref をつけるということがなかったので気が付いていませんでした。