-1

Can someone please explain why this line does not work

dest = await GetDestinationContext(pbx.Nodes.FirstOrDefault(x => x.Id == dests[normalTsCount++]));

But this does

dest = await GetDestinationContext(pbx.Nodes.FirstOrDefault(x => x.Id == dests[normalTsCount]));
normalTsCount++;

The first line gives an ArgumentOutOfRangeException the first time it runs.

NPovlsen
  • 337
  • 1
  • 16
  • 1
    Does this answer your question? [Pre- & Post Increment in C#](https://stackoverflow.com/questions/8573190/pre-post-increment-in-c-sharp) – mamen Feb 21 '23 at 10:15
  • 2
    @mamen the problem here has nothing to do with pre/post incrementation, it has to do with an incrementation being called multiple times because it is wrapped in a callback – sschwei1 Feb 21 '23 at 10:20
  • @sschwei1 You are right, my bad – mamen Feb 22 '23 at 08:55

1 Answers1

4

because at

dest = await GetDestinationContext(pbx.Nodes.FirstOrDefault(x => x.Id == dests[normalTsCount++]))

the normalTsCount++ incerements each iteration over Nodes

fubo
  • 44,811
  • 17
  • 103
  • 137