IndexOutOfRangeException থ্রো হয় যখন অ্যারের বৈধ ইনডেক্সের বাইরে অ্যাক্সেস করার চেষ্টা করা হয়। C#-এ অ্যারে ০-ভিত্তিক ইনডেক্সড।
উদাহরণ
using System;
using System.IO;
using System.Collections.Generic;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[5];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
arr[5] = 60; // এরর: ইনডেক্স ৫ বাইরে (সাইজ ৫, ইনডেক্স ০-৪)
}
}
}
আউটপুট (এরর)
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
প্রিভেনশন: লুপে arr.Length ব্যবহার করুন, হARDCODED ইনডেক্স এড়িয়ান, বাউন্ড চেক করুন।