out
StackOverflow に関するいくつかの C# の質問は、またはref
パラメーターを使用して匿名のデリゲート/ラムダを作成する方法を尋ねます。たとえば、次を参照してください。
これを行うには、次のようにパラメーターの型を指定するだけです。
public void delegate D(out T p);
// ...
D a = (out T t) => { ... }; // Lambda syntax.
D b = delegate(out T t) { ... }; // Anonymous delegate syntax.
私が興味を持っているのは、型が明示的に必要な理由です。これが事実である特定の理由はありますか?つまり、コンパイラ/言語の観点から、次のことが許可されないのはなぜですか?
D a = (out t) => { ... }; // Lambda syntax -- implicit typing.
D b = delegate(out t) { ... }; // Anonymous delegate syntax -- implicit typing.
またはさらに良いのは、次のとおりです。
D a = (t) => { ... }; // Lambda syntax -- implicit typing and ref|out-ness.
D b = delegate(t) { ... }; // Anonymous delegate syntax -- implicit typing and ref|out-ness.