How can I put the current value of a variable into a delegate?

Rene Zwanenburg renezwanenburg at gmail.com
Wed May 8 12:29:05 UTC 2024


On Monday, 6 May 2024 at 16:41:38 UTC, Steven Schveighoffer wrote:
> This is a very old issue: 
> https://issues.dlang.org/show_bug.cgi?id=2043 since "moved" to 
> https://issues.dlang.org/show_bug.cgi?id=23136
>
> I would love to see a solution, but the workaround at least 
> exists!
>
> -Steve

Interestingly enough C# used to have the same behaviour but MS 
decided to go for a breaking change in C# 5; now it behaves as 
most people expect.

Since it's an unsolved problem to keep links working for 10+ 
years I gave up looking for something official about the subject. 
Here's an SO question about it though:

https://stackoverflow.com/questions/14184515/action-delegate-uses-the-last-values-of-variables-declared-outside-foreach-loop




More information about the Digitalmars-d-learn mailing list