Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何同时使用键和值对SortedDictionary进行排序?_C#_Collections - Fatal编程技术网

C# 如何同时使用键和值对SortedDictionary进行排序?

C# 如何同时使用键和值对SortedDictionary进行排序?,c#,collections,C#,Collections,我有一个SortedDictionary,其中键是对类存储的引用。值为列表 我想把字典里的词库分类。 IComparer只能应用于键的值 但为了正确排序,需要值(列表)中的数据。比如价格 我该怎么做? 使用SortedDictionary可选,我将处理任何决策。 很重要的是,我可以快速获得一个键的值,类似地TryGetValue class Item { int price; string name; } class Store { string owner; string s

我有一个
SortedDictionary
,其中键是对类存储的引用。值为
列表

我想把字典里的词库分类。
IComparer
只能应用于
键的值

但为了正确排序,需要值(
列表
)中的数据。比如价格

我该怎么做? 使用SortedDictionary可选,我将处理任何决策。 很重要的是,我可以快速获得一个键的值,类似地
TryGetValue

class Item
{
  int price;
  string name;
}

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

SortedDictionary<Store, List<Item>>
类项目
{
国际价格;
字符串名;
}
班级商店
{
字符串所有者;
弦街;;
字符串城市;
}
分类词典

您可以使用LINQ扩展方法对存储列表进行排序,如
OrderBy
OrderByDescending

Dictionary<Store, List<Item>> stores;
...
var result = stores.OrderBy(pair => pair.Value.Min(item => item.price));
字典存储;
...
var result=stores.OrderBy(pair=>pair.Value.Min(item=>item.price));

也许
分类词典
?不,我需要对商店列表/词典进行分类。使用商品价格的数据。你可以将
列表
作为
商店
类的一部分作为字段,然后你就可以按照你想要的方式对商店列表进行排序。@Yuriy我考虑过了。但我不能合乎逻辑地这样做。列表是文本之后收到的文本的临时列表search@Mixer我看不出有什么问题。