Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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# 按描述顺序排序后获取SortedList类型 SortedList testIds=新的SortedList();_C#_Sorting_Collections - Fatal编程技术网

C# 按描述顺序排序后获取SortedList类型 SortedList testIds=新的SortedList();

C# 按描述顺序排序后获取SortedList类型 SortedList testIds=新的SortedList();,c#,sorting,collections,C#,Sorting,Collections,在按降序排序后,我可以获得SortedList收集类型吗? 例如: SortedList<string, object> testIds = new SortedList<string, object>(); SortedList SortedTestIds=testIds.OrderByDescending(t=>t.Key); 或者其他一些情况。您必须使用varlike SortedList<string, object> SortedTestIds

在按降序排序后,我可以获得SortedList收集类型吗? 例如:

SortedList<string, object> testIds = new SortedList<string, object>();
SortedList SortedTestIds=testIds.OrderByDescending(t=>t.Key);

或者其他一些情况。

您必须使用
var
like

SortedList<string, object> SortedTestIds = testIds.OrderByDescending(t=>t.Key);
或者,如果您想要SortedList,则必须为自己的比较器使用
IComparer


您可以在这里找到它

您可以使用var SortedTestIds=testIds.OrderByDescending(t=>t.Key);我知道var,但就我而言,我需要SortedList@Dhaval帕特尔,谢谢!可以给我一些建议,如何创建类似的比较器来对SortedList进行排序,不是为了键,而是为了值。
var SortedTestIds = testIds.OrderByDescending(t => t.Key);