How to get distinct values from an array in C#?

Posted by balajirnaukri-12656 under C# on 4/23/2012 | Points: 10 | Views : 7508 | Status : [Member] | Replies : 3
How to get distinct values from an array in C#?
[C#]

public int[] GetDistinctValues(int[] arr)
{
List<int> lst = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (lst.Contains(arr[i]))
continue;
lst.Add(arr[i]);
}
return lst.ToArray();
}

Thanks and Regards
Balaji.R
ASP.NET Devloper
Solve-IT corp



Responses

Posted by: Sakthi.Singaravel on: 4/23/2012 [Member] Silver | Points: 25

Up
0
Down
Thank u for choosing dotnetfunda...
please post ur questions and answers in interviews page..
Programs into codes page..

Regards,
Singaravel M

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/23/2012 [Member] Silver | Points: 25

Up
0
Down
for interview questions..

http://www.dotnetfunda.com/post/postexamquestion.aspx?csgagreed=true

Regards,
Singaravel M

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 4/23/2012 [Member] Silver | Points: 25

Up
0
Down
For code..

http://www.dotnetfunda.com/post/postcode.aspx?csgagreed=true

Regards,
Singaravel M

balajirnaukri-12656, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response