using System.Runtime.CompilerServices; int x = 1; _ = x.M(); // 拡張メソッドの this 引数は ref 渡しできる。 _ = (x * x).M(); // ref 渡しには右辺値は渡せないので M(ref int) を呼べない。 // M(int) の方呼んでほしいけどもダメっぽい。エラーに。 static class A { // 右辺値の時だけこっちを呼んでほしいけど、OverloadResolutionPriority でそういうことはできないっぽい。 [OverloadResolutionPriority(-1)] public static int M(this int x) => x + 1; public static int M(this ref int x) => x + 1; }