If I have a list List<KeyValuePair<string,string>>
ex.
["abc","123"]
["asc","123"]
["asdgf","123"]
["abc","123"]
how can I distinc this list?
List<int> myList = list. Distinct(). ToList();
A key-value pair consists of two related data elements: A key, which is a constant that defines the data set (e.g., gender, color, price), and a value, which is a variable that belongs to the set (e.g., male/female, green, 100). Fully formed, a key-value pair could look like these: gender = male. color = green.
Answer: A key-value pair (KVP) is a set of two linked data items: a key, which is a unique identifier for some item of data, and the value, which is either the data that is identified or a pointer to the location of that data. Key-value pairs are frequently used in lookup tables, hash tables and configuration files.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With