以下の内容はhttps://rksoftware.hatenablog.com/entry/2023/12/20/230000より取得しました。


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 をつけるということがなかったので気が付いていませんでした。




以上の内容はhttps://rksoftware.hatenablog.com/entry/2023/12/20/230000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14