c# Trying to reverse a list

后端 未结 7 1677
傲寒
傲寒 2020-12-13 11:44
public class CategoryNavItem
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Icon { get; set; }

    public CategoryNavItem(         


        
7条回答
  •  孤街浪徒
    2020-12-13 12:19

    Try:

    NavItems.Reverse();
    return NavItems;
    

    List.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();
    

提交回复
热议问题