Enumerated range in descending order

I bind combobox with enumerable.range() and it works fine. Now I'm trying to show the results in descending order, how can I do this?

  cboYearList.ItemsSource = Enumerable.Range( DateTime.Today.Year,1950).ToList().OrderByDescending(); 
+5
source share
1 answer

You can Reverse list after creating using Enumerable.Range :

 cboYearList.ItemsSource = Enumerable.Range(DateTime.Today.Year, 1950).Reverse().ToList(); 

Or, if you want to keep your OrderByDescending , you need to pass the key selector ( i => i at the end):

 cboYearList.ItemsSource = Enumerable.Range( DateTime.Today.Year,1950).OrderByDescending(i => i).ToList(); 
+6
source

Source: https://habr.com/ru/post/1214445/


All Articles