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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -