I have the following code:
var maxCodes = Math.Max(pCodes.Count, poCodes.Count);
for (var i = maxCodes - 1; i > -1; i--)
{
var code = (i < pCodes.Count) ? pCodes.ElementAt(i) : new pCodeDto();
//....
}
My issue is I am getting an ArgumentOutOfRangeException
and I am wondering if it could be being caused by the line of code with the ternary expression? This is an emailed exception from a client, so for now it is all I have.
I am wondering if the whole of this expression:
var code = (i < pCodes.Count) ? pCodes.ElementAt(i) : new pCodeDto();
gets evaluated before the code decides which route to go down, which could be a cause of this exception? This is single threaded code.
pCodes
and poCodes
are both ICollections