অ্যারে IndexOutofBoundsException জাভাতে ঘটে। C# তে এর সমতুল্য হল IndexOutOfRangeException.
IndexOutOfRangeException তখন ঘটে যখন সূচক অ্যারের সীমার বাইরে থাকে।
উদাহরণ
using System;
using System.IO;
using System.Collections.Generic;
namespace Demo {
class Program {
static void Main(string[] args) {
int[] arr = new int[3];
arr[0] = 5;
arr[1] = 7;
arr[2] = 8;
arr[4] = 24; // this shows an error
}
}
} আউটপুট
নিম্নলিখিত আউটপুট. এটি নিম্নলিখিত ত্রুটি দেখায় -
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.