问题
I want to remove duplicates from this list:
List<Dictionary<string, object>> val = new List<Dictionary<string, object>>();
It does not work if I apply Distinct() in this way:
List<Dictionary<string, object>> result = val.Distinct().ToList<Dictionary<string, object>>()
Update: Problem is now solved. I used the MySQL union command to read table from the database.
回答1:
Try this:
List<Dictionary<string, object>> result = val.Distinct(new myDictionaryComparer()).ToList();
where myDictionaryComparer
is a Comparer Class. You can implement your comparison logic in this class.
回答2:
You can use the following method:
val.Distinct()
来源:https://stackoverflow.com/questions/2756458/how-to-remove-duplicates-from-a-list-in-c-sharp