c# Trying to reverse a list

c# Trying to reverse a list


return NavItems;

List<T>.Reverse() is an in-place reverse; it doesnt 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();

c# Trying to reverse a list

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

Leave a Reply

Your email address will not be published.