Is there a easy way to filter out unique elements using linq? -
i have xml document
<numset> <num>1</num> <num>2</num> <num>2</num> <num>3</num> </numset>
i want unique elements shown up, ie 1 , 3. not distinct bring out 2. how that? have use group? there concise way that?
you right, can use groupby
, filter group has 1 item using count() == 1
:
var output = xdocument.load(xmlfile) .descendants("num") .select(e => e.value) .groupby(x => x) .where(g => g.count() == 1) .select(g => g.key);
Comments
Post a Comment