Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reversing an ObservableCollection<objectType> using linq

This one should be easy, and im ashamed i havent figured it out myself yet. I'm trying to reverse the order of a list of items in my wp7 app. The list is an ObservableCollection. When using system.linq, intellisense lets me do this: myList.Reverse(); ,but this doesnt seem to work. Am i doing something wrong, or is there some other way i can do this easily?

Thanks in advance.

like image 685
Hans Petter Naumann Avatar asked Jul 10 '12 22:07

Hans Petter Naumann


1 Answers

Reverse returns an IEnumerable, it does not modify the collection. To modify the collection you could do

collection = new ObservableCollection<YourType>(collection.Reverse());
like image 107
Shawn Kendrot Avatar answered Oct 13 '22 01:10

Shawn Kendrot