IndexOutOfRangeException is most commonly thrown when attempting to access an index greater than or equal to the length of an array or list, or below 0.
int[] numbers = new int[] { 0, 1, 3 };
Console.WriteLine(numbers[2]); // 3
Console.WriteLine(numbers[3]); // IndexOutOfRangeException
It could be a for loop or an attempt to access the first element in an empty array (emptyarray[0] also throws).
foreach should not be able to throw this exception as it does not work by index (it has a different exception for collection length changing while looping)