Index was outside the bounds of array

Last Reply on Jun 26, 2012 07:00 AM By Mudassar

Posted on Jun 26, 2012 04:15 AM
public static void Main()
        {
            int[] number={1,1,3,3,3,5,5,5,9,9,9,9};
            int n = number.Length;
            for (int i = 0; i < n; i++)
            {
                if (number[i] != number[i + 1])
                {
                    Console.WriteLine(number[i]);

                }
                    
                   
            }

        }

Please correct me

Posted on Jun 26, 2012 04:17 AM
public static void Main()
{
    int[] number = { 1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9 };
    int n = number.Length;
    for (int i = 0; i < n; i++)
    {
        if ((i + 1) < n && number[i] != number[i + 1])
        {
            Console.WriteLine(number[i]);

        }
    }
}

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html