score:344

Accepted answer
ienumerable<int> ids = list.select(x=>x.id).distinct();

score:2

int[] numbers = {1,2,3,4,5,3,6,4,7,8,9,1,0 };
var nonrepeats = (from n in numbers select n).distinct();

foreach (var d in nonrepeats)
{

    response.write(d);
}

output

1234567890

score:2

when taking distinct, we have to cast into ienumerable too. if the list is <t> model, it means you need to write code like this:

 ienumerable<t> ids = list.select(x => x).distinct();

score:13

using straight linq, with the distinct() extension:

var idlist = (from x in yourlist select x.id).distinct();

score:30

use the distinct operator:

var idlist = yourlist.select(x=> x.id).distinct();

Related Query