Do lambdas paste?

make simple lambda expressions inline?

I have a tendency (thanks to f # and other functional incursions) to encapsulate repeating code present in one function in lambda and call it instead. I am curious if as a result there will be overhead at runtime:

var foo = a + b;
var bar = a + b;

v

Func<T1, T2> op = () => a + b;
var foo = op();
var bar = op();

which one is worth more?

+5
source share
2 answers

No. Lambda functions are not built-in, but instead are stored as delegates under the hood and carry the same execution cost as other delegates.

+3
source

: . . . , , "" , , . , , , .

: , .

-, # - . jit , , # lambdas , , , . (, , , , , .)

, , . , , , , .

, , . , , , .

+7

All Articles