Error Index was outside the bounds of the array. Program is to remove duplicates from an array I understand the error which is that line 32 where an extra element is created at the end of the for loop but i am unable to figure out a way to display the whole array without the duplicates. What the prog is suppose to do is inputs a 5 number into an array and then sorts them and if their are duplicates it removes it. I hope i made it clear!
using System;
class duplicate
{
static void Main()
{
const int Array_Size = 5;
int [] number = new int [Array_Size];
int i;
for ( i = 0; i < Array_Size; i++)
{
number[i] = Int32.Parse(Console.ReadLine());
if (number[i] < 9 || number[i] > 101)
{
Console.WriteLine("Enter Number between 10 - 100");
number[i] = Int32.Parse(Console.ReadLine());
}
}
Array.Sort(number);
Console.WriteLine("Sorted Array : ");
for (i = 0; i < Array_Size; i++)
{
Console.WriteLine("Element is " + number[i]);
}
Console.WriteLine("Duplicate Removed : ");
for (i = 0; i < Array_Size; i++)
{
if (number[i] != number[i+1])
Console.WriteLine("Element is " + number[i]);
}
Console.ReadLine();
}
}