ArgumentOutOfRangeException List error c#

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.

>Solution :

because at

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

the normalTsCount++ incerements each iteration over Nodes

Leave a Reply