The implementation of anonymous methods in C# and its consequences

When we use anomymous lambda in C#, we can have to choose between passing values as parameter or using lambda capture. Second one is elegant and easy: we “just” us enclosing variables.

It is good to remember that capturing has a cost which should be understood and taken into account. For this, we can refer to : The implementation of anonymous methods in C# and its consequences – The Old New Thing.

Knowing this, we can think that C++ 11 solution is better. We have to choose wich variables are captured and if capture is a copy or a modifiable reference in capture specification block ([]).  And, by default, there is no capture. That way, overhead it is not a hazard but a deliberate choice. Perhaps for C# 7 but with breaking changes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s