2017-12-13 8 views
0

나는 MVC와 함께 RSS를 사용하여 wired.com에서 피드를 얻고있다. 하지만 나는 모두 먹일 필요가 없다. 나는 처음 다섯 개의 먹이가 필요하다. 어떻게해야합니까?RSS get First Five Item

 WebClient wclient = new WebClient(); 
     string RSSData = wclient.DownloadString("https://www.wired.com/feed/rss"); 
     return View(); 

     Document xml = XDocument.Parse(RSSData); 
     var RSSFeedData = (from x in xml.Descendants("item") 
          select new RSSFeed 
          { 
           Title = ((string)x.Element("title")), 
           Link = ((string)x.Element("link")) 
          }); 

답변

0

Enumerable.Take (int)를 사용할 수 있습니다. 요소

여기
IEnumerable<RSSFeed> RSSFeedData = (from x in xml.Descendants("item") 
          select new RSSFeed 
          { 
           Title = ((string)x.Element("title")), 
           Link = ((string)x.Element("link")) 
          }).Take(5); 

문서 https://msdn.microsoft.com/it-it/library/bb503062(v=vs.110).aspx

지정된 수를 반환