L
L
LemanRass212018-05-27 22:01:17
C++ / C#
LemanRass21, 2018-05-27 22:01:17

Where did the problem of closures in C# go?

I remember studying closures in C# a couple of months ago.
A rather problematic topic for a quick understanding.
But at that time I figured it out thanks to this post on Habré:
https://habr.com/post/36601/
Now I decided to refresh my memory, because during this time closures were not useful to me in practice. But this is a topic that you need to know whether you use it or not. Favorite interview question.
So, the essence of the problem ... the example from Habr no longer demonstrates the problem of closures.
In other words, even the first example (which is tricky) gives me the correct result (1 2 3 4).
What exactly did I miss?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2018-05-27
@LemanRass21

Starting with C# version 5.0, variables declared in "foreach" are considered to be internal variables of the loop. Those. there is no more closure.
https://m.habr.com/post/141270/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question