Ok、非常にばかげた質問です。void入力のラムダ式
x => x * 2
は
int Foo(x) { return x * 2; }
ためのデリゲートと同じことを表すラムダである。しかし
int Bar() { return 2; }
のラムダ同等は何ですか?
ありがとうございます!
Ok、非常にばかげた質問です。void入力のラムダ式
x => x * 2
は
int Foo(x) { return x * 2; }
ためのデリゲートと同じことを表すラムダである。しかし
int Bar() { return 2; }
のラムダ同等は何ですか?
ありがとうございます!
ヌルラムダ相当物は() => 2
となる。
次のようになります。
() => 2
使用例:
var list = new List<int>(Enumerable.Range(0, 10));
Func<int> x =() => 2;
list.ForEach(i => Console.WriteLine(x() * i));
コメントで要求されるように、ここでは上記のサンプルの内訳は、だ...
// initialize a list of integers. Enumerable.Range returns 0-9,
// which is passed to the overloaded List constructor that accepts
// an IEnumerable<T>
var list = new List<int>(Enumerable.Range(0, 10));
// initialize an expression lambda that returns 2
Func<int> x =() => 2;
// using the List.ForEach method, iterate over the integers to write something
// to the console.
// Execute the expression lambda by calling x() (which returns 2)
// and multiply the result by the current integer
list.ForEach(i => Console.WriteLine(x() * i));
// Result: 0,2,4,6,8,10,12,14,16,18
こんにちは、これは偉大な例のように思えます。普通の英語で行ごとに、ひとつずつ説明できますか? :) – PussInBoots
@PussInBootsはいくつかのコメントを追加しました。希望が助けてくれる! –
ありがとうございます。まだ少しFunc
あなたはすることができますパラメータがない場合はuse()を使用してください。
lmabdaは次のとおりです。
() => 2
くそ、それは速かった:)ありがとうみんな! – Luk