rani m  mk

rani m mk

  • NA
  • 50
  • 42.6k

Index out of range error

Jun 26 2012 6:00 AM

Hi all,

This is the code below which gives me the error mentioned in subject:
Here i want to extract the unique elements: output should be {1,3,5,9}
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]);

                }
                   
                  
            }

        }

Thanks in advance

Answers (10)