How to handle 'indexoutofrangeexception in c#'?

Example:

int[] arr = new int[5];
int value = arr[10];
Solution:

This error is thrown when trying to access an index outside the bounds of an array. Always check the array length before accessing its elements.


if(index < arr.Length) {
    int value = arr[index];
}

Beginner's Guide to C#