Click here to Skip to main content
15,882,658 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Wordle 990 Pin
Sander Rossel4-Mar-24 21:31
professionalSander Rossel4-Mar-24 21:31 
GeneralRe: Wordle 990 - 4 4 me lucky guess Pin
pkfox4-Mar-24 22:18
professionalpkfox4-Mar-24 22:18 
GeneralRe: Wordle 990 Pin
Cp-Coder5-Mar-24 0:26
Cp-Coder5-Mar-24 0:26 
GeneralOde to orange kitties - well, one in particular PinPopular
honey the codewitch4-Mar-24 13:24
mvahoney the codewitch4-Mar-24 13:24 
GeneralRe: Ode to orange kitties - well, one in particular Pin
englebart4-Mar-24 14:12
professionalenglebart4-Mar-24 14:12 
GeneralRe: Ode to orange kitties - well, one in particular Pin
Ron Anders4-Mar-24 14:42
Ron Anders4-Mar-24 14:42 
GeneralRe: Ode to orange kitties - well, one in particular Pin
charlieg7-Mar-24 10:16
charlieg7-Mar-24 10:16 
GeneralClosures (C#) Pin
Marc Clifton4-Mar-24 3:56
mvaMarc Clifton4-Mar-24 3:56 
I love closures and lambdas, but I was quite amused when I wrote the following buggy code:
for (int i=0; i <= 10; i++)
{
    var task = Task.Run(async () =>
    {
      var convertResp = await StartTestConvert(i);
      ... other stuff
    });
}
And was wondering, how in the world does i get equal to 11!!! Laugh | :laugh:

Answer: bad closure. Fix:
for (int i=0; i <= 10; i++)
{
    int n = i;
    var task = Task.Run(async () =>
    {
      var convertResp = await StartTestConvert(n);
      ... other stuff
    });
}


I think this would make a good interview question!


modified 4-Mar-24 10:13am.

GeneralRe: Closures (C#) Pin
Richard Deeming4-Mar-24 4:20
mveRichard Deeming4-Mar-24 4:20 
GeneralRe: Closures (C#) Pin
Marc Clifton4-Mar-24 7:49
mvaMarc Clifton4-Mar-24 7:49 
JokeRe: Closures (C#) Pin
0x01AA4-Mar-24 6:05
mve0x01AA4-Mar-24 6:05 
GeneralRe: Closures (C#) Pin
Sander Rossel4-Mar-24 8:59
professionalSander Rossel4-Mar-24 8:59 
GeneralRe: Closures (C#) Pin
jmaida4-Mar-24 12:29
jmaida4-Mar-24 12:29 
GeneralRe: Closures (C#) Pin
Stacy Dudovitz5-Mar-24 17:31
professionalStacy Dudovitz5-Mar-24 17:31 
GeneralRe: Closures (C#) Pin
Jeremy Falcon4-Mar-24 12:50
professionalJeremy Falcon4-Mar-24 12:50 
GeneralRe: Closures (C#) Pin
jmaida4-Mar-24 15:00
jmaida4-Mar-24 15:00 
GeneralRe: Closures (C#) Pin
Jeremy Falcon4-Mar-24 17:53
professionalJeremy Falcon4-Mar-24 17:53 
GeneralRe: Closures (C#) Pin
jmaida4-Mar-24 15:41
jmaida4-Mar-24 15:41 
GeneralRe: Closures (C#) Pin
Jeremy Falcon4-Mar-24 17:54
professionalJeremy Falcon4-Mar-24 17:54 
GeneralRe: Closures (C#) Pin
Jacquers4-Mar-24 17:43
Jacquers4-Mar-24 17:43 
GeneralRe: Closures (C#) Pin
englebart4-Mar-24 14:40
professionalenglebart4-Mar-24 14:40 
GeneralRe: Closures (C#) Pin
Peter Adam4-Mar-24 20:20
professionalPeter Adam4-Mar-24 20:20 
GeneralRe: Closures (C#) Pin
Fly Gheorghe4-Mar-24 21:36
Fly Gheorghe4-Mar-24 21:36 
GeneralRe: Closures (C#) Pin
RooN3y5-Mar-24 2:18
RooN3y5-Mar-24 2:18 
GeneralRe: Closures (C#) Pin
Rich Shealer5-Mar-24 3:14
Rich Shealer5-Mar-24 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.