Accessing an array or list element using an index smaller than 0 or greater than or equal to its length.
Thrown when an attempt is made to access an element of an array or collection with an index that is outside its boundaries.
Off-by-one errors in `for` loops (using `<= array.Length`), assuming an array returned from a method has elements without checking `array.Length > 0`.
1using System;2 3public class Program {4 public static void Main() {5 int[] numbers = { 10, 20, 30 };6 for (int i = 0; i <= numbers.Length; i++) { // <= is wrong!7 Console.WriteLine(numbers[i]); // Throws IndexOutOfRangeException on last iteration8 }9 }10}1using System;2 3public class Program {4 public static void Main() {5 int[] numbers = { 10, 20, 30 };6 7 // Fix 1: Use strictly less than (<)8 for (int i = 0; i < numbers.Length; i++) {9 Console.WriteLine(numbers[i]);10 }11 12 // Fix 2: Prefer foreach iteration13 foreach (var num in numbers) {14 Console.WriteLine(num);15 }16 }17}Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
For an array of length 3, valid indices are 0, 1, and 2. When `i` reaches 3 (`i <= numbers.Length`), accessing `numbers[3]` throws `IndexOutOfRangeException`.