Я использую следующий код:Еогеасп заявление дает ошибку
private string covertRss(string url)
{
var s = RssReader.Read(url);
StringBuilder sb = new StringBuilder();
foreach (RssNews rs in s) //ERROR LINE
{
sb.AppendLine(rs.Title);
sb.AppendLine(rs.PublicationDate);
sb.AppendLine(rs.Description);
}
return sb.ToString();
}
Я получаю сообщение об ошибке:
Error 1 foreach statement cannot operate on variables of type 'System.Threading.Tasks.Task(System.Collections.Generic.List(Cricket.MainPage.RssNews))' because 'System.Threading.Tasks.Task(System.Collections.Generic.List(Cricket.MainPage.RssNews))' does not contain a public definition for 'GetEnumerator'
Класс RssNews является:
public class RssNews
{
public string Title;
public string PublicationDate;
public string Description;
}
Что код должен Я добавлю, что ошибка удалена, и цель кода не компилируется? Спасибо заранее!
Код для RssReader.Read()
public class RssReader
{
public static async System.Threading.Tasks.Task<List<RssNews>> Read(string url)
{
HttpClient httpClient = new HttpClient();
string result = await httpClient.GetStringAsync(url);
XDocument document = XDocument.Parse(result);
return (from descendant in document.Descendants("item")
select new RssNews()
{
Description = descendant.Element("description").Value,
Title = descendant.Element("title").Value,
PublicationDate = descendant.Element("pubDate").Value
}).ToList();
}
}
Что 'RssReader.Read' возвращается? – Habib
хотя программа не работает. Она предназначена для чтения из фида, всего xml фида. – YashVj
Опубликуйте свой код для метода 'RssReader.Read()'. –