How to find distinct values from array C# Linq

Posted by Laghaterohan under C# on 7/17/2013 | Points: 10 | Views : 14566 | Status : [Member] | Replies : 1
Hi,
one of my method returns me an array which has several fields say, id1, id2 ,id3 etc...
how I want to make list of distinct ids from this id1,id2,id3. Can any one help me out how to do this using C#, LINQ ??

Please help.

Best Regards,
Rohan Laghate



Responses

Posted by: Prabhat39 on: 7/17/2013 [Member] Starter | Points: 25

Up
0
Down
You can use distinct() method of linq. Below is the sample code.
int[] num = {1,3,4,2,4,2,4,5,2};
var disNum = num.Distinct();
foreach (int i in disNum)
{
Console.WriteLine(i);
}

Regards,
Prabhat Kumar

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response