2013-12-15 47 views
0

我有一个SortedDictionary其中密钥是对类商店的引用。值为List<Item>如何使用键和值一起对SortedDictionary进行排序?

我想排序字典中的商店。 IComparer只能应用于Key的值。

但是,对于正确的排序,需要Value(List<Item>)中的数据。价格为例。

我该怎么做? 使用SortedDictionary可选,我会处理任何决定。 重要的是,我可以快速获得钥匙的价值,类似于TryGetValue

class Item 
{ 
    int price; 
    string name; 
} 

class Store 
{ 
    string owner; 
    string street; 
    string city; 
} 

SortedDictionary<Store, List<Item>> 
+0

也许'SortedDictionary <商店,SortedSet的>'? –

+0

不,我需要对商店的列表/字典进行排序。使用货物价格的数据。 – Mixer

+0

您可以将'Store'类的'List '部分作为字段,然后您就可以按照自己想要的方式对商店列表进行排序。 – Yuriy

回答

0

那么你可以进行排序使用LINQ扩展方法像OrderByOrderByDescending存储列表:

Dictionary<Store, List<Item>> stores; 
... 
var result = stores.OrderBy(pair => pair.Value.Min(item => item.price)); 
相关问题