Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

public class CategoryNavItem
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string Icon { get; set; }

    public CategoryNavItem(int CatID, string CatName, string CatIcon)
    {
        ID = CatID;
        Name = CatName;
        Icon = CatIcon;
    }
}

public static List<Lite.CategoryNavItem> getMenuNav(int CatID)
{
    List<Lite.CategoryNavItem> NavItems = new List<Lite.CategoryNavItem>();

    -- Snipped code --

    return NavItems.Reverse();
}

The reverse doesn't work:

Error 3 Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<Lite.CategoryNavItem>'

Any ideas why this might be?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
107 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...