c# Trying to reverse a list

Try:

NavItems.Reverse();
return NavItems;

List<T>.Reverse() is an in-place reverse; it doesn't return a new list.

This does contrast to LINQ, where Reverse() returns the reversed sequence, but when there is a suitable non-extension method it is always selected in preference to an extension method. Plus, in the LINQ case it would have to be:

return someSequence.Reverse().ToList();

One workaround would be Return NavItems.AsEnumerable().Reverse();


.Reverse() on a list reverses the items within the list, it does not return a new reversed list.

Tags:

C#

List

Reverse