c# Trying to reverse a list

后端 未结 7 1653
傲寒
傲寒 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条回答
  •  萌比男神i
    2020-12-13 12:23

    If you have a list like in your example:

    List NavItems
    

    You can use the generic Reverse<> extensions method to return a new list without modifiying the original one. Just use the extension method like this:

    List reversed = NavItems.Reverse();
    

    Notes: You need to specify the <> generic tags to explicit use the extension method. Don't forget the

    using System.Linq;
    

提交回复
热议问题