If I have a list List<KeyValuePair<string,string>>
ex.
["abc","123"]
["asc","123"]
["asdgf","123"]
["abc","123"]
how can I distinc this list?
If I have a list List<KeyValuePair<string,string>>
ex.
["abc","123"]
["asc","123"]
["asdgf","123"]
["abc","123"]
how can I distinc this list?
Distinct by both Key
and Value
:
var results = source.Distinct().ToList();
Distinct by Key
or Value
(just change the property on GroupBy
call:
var results = source.GroupBy(x => x.Key).Select(g => g.First()).ToList();
You should use a Set (of pair objects) if you wish to have distinct pairs or a Map/Dictionary if you wish to have distinct keys.