- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Understanding Array IndexOutofBoundsException in C#
Array IndexOutofBoundsException occurs in Java. The equivalent of it in C# is IndexOutOfRangeException.
The IndexOutOfRangeException occurs when Index is outside the bounds of the array.
Example
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 } } }
Output
The following is the output. It shows the following error −
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Advertisements