Console.WriteLine("Enter the number");
int num = Convert.ToInt32(Console.ReadLine());
int[] array = new int[num];
Array.Sort(array);
for(int i = 0;i < array[i] ;i++)
{
if (array[0] == array[i])
{
}
}
I have sorted and i am comparing every element of the array with the next element.
But how to remove the duplicate element??

VulpesPosted Nov 25, 2012, 9:58 AM
To remove duplicate elements, you need to convert the array to a List. You also need to iterate backwards through the list to avoid messing up the indexing of those elements which are yet to be examined.
The following program does that and also shows how simple something like this has become since the introduction of LINQ. Notice that LINQ doesn't need to sort the elements first - they maintain their original order.
The output should be: