C# program
Can someone please tell me the efficient code for extracting unique elements
from a sorted list of array. e.g. (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9) ->
(1, 3, 5, 9)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Dec 28, 2009, 10:36 PM
Friend,
Here is your Solution Please check "Do you like this answer" check box if my answer helps you :) it helps me .
Thanks
int[] numArray = { 1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9 };
List<int> UniqElements = new List<int>();
UniqElements.Clear();
foreach (int i in numArray)
{
if (!UniqElements.Contains(i))
{
UniqElements.Add(i);
}
}
// Now Use it
foreach (int i in UniqElements)
{
Console.WriteLine(i.ToString());
}
Console.ReadKey();
Here is Output
---------------
VishuPosted Dec 29, 2009, 12:44 AM