views:

217

answers:

2

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.

A: 

Try val.Distinct()

alejandrobog
i apply it but he not worked really.
4thpage
Are the repeated items the same instance?
alejandrobog
+1  A: 

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.

Veer
You don't necessarily need to wrap your dictionary in MyClass. You can simply define a class implementing IEqualityComparer<Dictionary<string, object>> and pass it to Distinct
digEmAll
@digEmAll: Yes! what you say is more relevant in this scenario. Thanks. Check my edit.
Veer