, , , , , , , .
, , . LINQ Except(), , .
public static IEnumerable<T> ExceptSingle<T>(this IEnumerable<T> source, T valueToRemove)
{
return source
.GroupBy(s => s)
.SelectMany(g => g.Key.Equals(valueToRemove) ? g.Skip(1) : g);
}
: {"one", "two", "three", "three", "three"}
source.ExceptSingle("three") {"one", "two", "three", "three"}
: {"one", "two", "three", "three"}
source.ExceptSingle("three") {"one", "two", "three"}
: {"one", "two", "three"}
source.ExceptSingle("three") {"one", "two"}
: {"one", "two", "three", "three"}
source.ExceptSingle("four") {"one", "two", "three", "three"}