wpf 按降序排列的可枚举范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28802287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Enumerable range in descending order
提问by Pierre-Luc Pineault
I am binding a combobox using enumerable.range()and it works fine.
Now I am trying to display the results in descending order, how can I do that?
我正在使用绑定一个组合框enumerable.range(),它工作正常。现在我试图以降序显示结果,我该怎么做?
cboYearList.ItemsSource = Enumerable.Range( DateTime.Today.Year,1950).ToList().OrderByDescending();
回答by Pierre-Luc Pineault
You can Reversethe list after creating it with Enumerable.Range:
您可以使用Reverse以下命令创建列表Enumerable.Range:
cboYearList.ItemsSource = Enumerable.Range(DateTime.Today.Year, 1950).Reverse().ToList();
Or if you want to keep your OrderByDescending, you need to pass a key selector (the i => iat the end):
或者如果你想保留你的OrderByDescending,你需要传递一个键选择器(i => i在最后):
cboYearList.ItemsSource = Enumerable.Range( DateTime.Today.Year,1950).OrderByDescending(i => i).ToList();

