Reversing ObservableCollection <objectType> using linq

It should be easy, and I am ashamed that I have not figured it out yet. I am trying to reorder the list of items in my wp7 application. A list is an ObservableCollection. When using system.linq, intellisense allows me to do this: myList.Reverse (); but this does not seem to work. Am I doing something wrong, or can I do it another way?

Thanks in advance.

+5
source share
3 answers

The reverse returns IEnumerable; it does not modify the collection. To change the collection you can do

collection = new ObservableCollection<YourType>(collection.Reverse());
+23
source

If you do not want to recreate the collection:

for (int i = 0; i < collection.Count; i++)
  collection.Move(collection.Count - 1, i);
+2

, ( T) . vb.net:

    Public Sub Sort(ByVal comparer As IComparer(Of T))
    Dim j As Integer
    Dim index As T
    For i As Integer = 1 To Count - 1
        index = Me(i)
        j = i
        While (j > 0) AndAlso (comparer.Compare(Me(j - 1), index) = 1)
            Me(j) = Me(j - 1)
            j = j - 1
        End While
        Me(j) = index
    Next
End Sub
0

All Articles