After reading answers to this question, one thing is unclear to me. User David Arno states that in the following situation the compiler will generate more IL code for method X, because of additional curly braces.
public Func<int> X()
{
{
var i = 1;
{
i++;
{
return () => i;
}
}
}
}
public Func<int> Y()
{
var i = 1;
i++;
return () => i;
}
I can't see the difference between those two pieces of code. To me it looks like you could safely remove all the braces from X. Which pair of braces is responsible for the additional IL code? I think the snippet would be clearer if X had just one pair of braces more than Y (I assume that it would be enough to prove the point).