c# 4.0 - Remove only one element from string array using linq -


i have following code:

string[] s = {"one", "two", "three", "two", "four"};  s = s.where(x => x!="two").toarray();  

i want remove "two" once using linq there way this? code tried above removes both "two" elements array.

well, maybe want remove duplicates in general, it's simple:

s = s.distinct().toarray(); 

otherwise can use groupby:

s = s.groupby(str => str).selectmany(g => g.key != "two" ? g : g.take(1)).toarray(); 

this allows duplicates in general, two must unique.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -