How to check if array index is out of range in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[] array = { 3, 91, 7, 8, 99, 10};
        
        int index = 5;
        if (index >= 0 && index < array.Length) {
            Console.Write("Not out of range");
        }
 
        
    }
}
 
 
 
 
/*
run:
 
Not out of range
 
*/

 



answered Aug 17, 2023 by avibootz
...