开发者

GetByLatest in LINQ?

开发者 https://www.devze.com 2022-12-23 22:29 出处:网络
Please provide me a solution for GetByLatest it is giving me an error How to use this \"GetByLatest\" IList<IRss> news = new Try开发者_运维知识库table().GetByLatest().Cast<IRss>().ToList

Please provide me a solution for GetByLatest it is giving me an error

How to use this "GetByLatest"

IList<IRss> news = new Try开发者_运维知识库table().GetByLatest().Cast<IRss>().ToList();

i used this way in the controller,still it is giving an error for getbylatest in the feed method

public static IEnumerable GetByLatest(this IEnumerable unsorted) { return from item in unsorted orderby item.Link descending select item; } public ActionResult Feed() {

        IEnumerable<IRss> news = new IEnumerable<IRss>.GetByLatest().Cast<IRss>().ToList();

            //IList<IRss> news = new Trytable().GetByLatest().Cast<IRss>();
            //return new RssResult(news, "William Duffy - Glasgow Based ASP.NET Web Developer", "The latest news on ASP.NET, C# and ASP.NET MVC ");

    }

please help me

Thanks Ritz


Assuming that the publication date for an individual RSS item is in the property PubDate and Trytable() returns an IEnumerable<IRss>, GetByLatest would look something like this:

public static IEnumerable<IRss> GetByLatest(this IEnumerable<IRss> unsorted)
{
    return from item in unsorted
           orderby item.PubDate descending
           select item;
}


It should be IEnumerable<IRss>, not IList<IRss>. Or, better yet, use var.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号