Monday 14 January 2013

Lambda Expressions Resolution in C#

Consider the code:


How this type of lambda expression is translated by the C# compiler?
The compiler internally resolves this type of lambda expressions by writing a private method and moving the expressions's code into that method.
It is possible to verify this using a free .NET decompiler like dotPeek.


Why this is relevant?

I am a strong believer that is important to understand what happens under the covers because it gives you a broader perspective and a better awareness of how the code works.

There are plenty of features of the C# languages that actually maps themselves to a subset of the C# language. This is one of the best thing of C# because this features usually improve significantly the developers productivity. The price is that something magic happens under the cover and this is why is important to learn about them.

No comments:

Post a Comment

What you think about this post? I really appreciate your constructive feedback (positive and negative) and I am looking forward to start a discussion with you on this topic.