Remove Duplicates From an int array

Nov 2 2008 12:09 AM

I am begginner in C# and I need your help on writing a program which will remove the duplicates from an integer array?

 

I tried but not sure how will I assign Null value to int type?

public void RemoveDuplicates(int[] A)

{

for (int i = 0, j = A.Length - 1; i <= j; i++, j--)

{

if (A[i] == A[j])

{

A[j] = 0;

}

Console.WriteLine(A[i]);

}

}

 

 

I also tried using an ArrayList where I will check if the arraylist already contains the element if not add else do nothing.

 

Thanks for your time in advance

 

 


Answers (1)