I want to reverse the order of items in an observable collection. This is my sample code:
int[] collection1 = new int[] { 1, 2, 3, 4, 5 };
ObservableCollection<int> obColl1 = new ObservableCollection<int>();
foreach ( var item in collection1 ) // initial order 1,2,3,4,5
{
obColl1.Add(item);
Console.WriteLine("Added {0} in ObservableCollection", item);
}
Console.WriteLine("Now reverse their order");
obColl1.Reverse();
foreach ( var item in obColl1 ) // still show 1,2,3,4,5 instead of 5,4,3,2,1
{
Console.WriteLine("After reversing ObservableCollection: {0}", item);
}
Console.WriteLine("Press any key to exit");
Console.ReadKey();
The output result shows still the same order as initial order. Am I missing something? some mistakes?
Thank you in advance