জাভায় ArrayIndexOutOfBoundsException হয়, C#-এ তার সমতুল্য 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; // এরর: ইনডেক্স ৪ বাইরে (সাইজ ৩, ইনডেক্স ০-২)
}
}
}
আউটপুট (এরর)
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
জাভা এবং C#-এ একই কনসেপ্ট, শুধু এক্সেপশন নাম ভিন্ন।