Where did the issue of closures in C#?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
32 views
I remember a couple months ago studied closures in C#.
Quite problematic to quickly understand the subject.
But at the time I figured out thanks to this post on habré:
https://habr.com/post/36601/

Now here I decided to refresh my memory, because I so, in practice, and not useful circuit. But it is a topic that needs to know regardless of whether you use it or not. A favorite question at interviews.

So, the crux of the problem...an example of Habra no longer demonstrates the issue of closures.
In other words, even the first example (that trick) I have displays the correct result (1 2 3 4).
What exactly did I miss?
by | 32 views

1 Answer

0 like 0 dislike
Starting with C# 5.0, variables declared in "foreach", are considered as internal variables of the loop. I.e., the circuit is no longer here.

\rhttps://m.habr.com/post/141270/
by
110,608 questions
257,186 answers
0 comments
38,662 users