class Program { static void Main() { var actions = new List<Action>();
for (int i = 0; i < 3; i++) { actions.Add(() => Console.WriteLine(i)); }
foreach (var action in actions) action(); } }
Варианты ответа: A)
1 2
B)
3 3
C)
0 0
D)
---
✅ Правильный ответ: B
Почему: Лямбда-функции захватывают переменную i по ссылке, а не её значение на каждой итерации. После завершения цикла i == 3, и все замыкания ссылаются на одно и то же i. Это классическая ловушка замыканий в C#.
class Program { static void Main() { var actions = new List<Action>();
for (int i = 0; i < 3; i++) { actions.Add(() => Console.WriteLine(i)); }
foreach (var action in actions) action(); } }
Варианты ответа: A)
1 2
B)
3 3
C)
0 0
D)
---
✅ Правильный ответ: B
Почему: Лямбда-функции захватывают переменную i по ссылке, а не её значение на каждой итерации. После завершения цикла i == 3, и все замыкания ссылаются на одно и то же i. Это классическая ловушка замыканий в C#.
BY C# 1001 notes
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
The S&P 500 slumped 1.8% on Monday and Tuesday, thanks to China Evergrande, the Chinese property company that looks like it is ready to default on its more-than $300 billion in debt. Cries of the next Lehman Brothers—or maybe the next Silverado?—echoed through the canyons of Wall Street as investors prepared for the worst.
If riding a bucking bronco is your idea of fun, you’re going to love what the stock market has in store. Consider this past week’s ride a preview.The week’s action didn’t look like much, if you didn’t know better. The Dow Jones Industrial Average rose 213.12 points or 0.6%, while the S&P 500 advanced 0.5%, and the Nasdaq Composite ended little changed.