Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一个清单List<KeyValuePair<string,string>>前。
List<KeyValuePair<string,string>>
["abc","123"] ["asc","123"] ["asdgf","123"] ["abc","123"]
我怎样才能区分这个列表?
两者不同Key和Value:
Key
Value
var results = source.Distinct().ToList();
区别于Key或Value(只需更改GroupBy待命属性:
GroupBy
var results = source.GroupBy(x => x.Key).Select(g => g.First()).ToList();
如果你希望有不同的对,你应该使用一个 Set(对对象),如果你希望有不同的键,你应该使用 Map/Dictionary。