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
Post a Comment