我使用以下代码:
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();
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
错误1 foreach语句无法对类型为"System.Threading.Tasks.Task(System.Collections.Generic.List(Cricket.MainPage.RssNews))"的变量进行操作,因为'System.Threading.Tasks.Task(System.Collections.Generic) .List(Cricket.MainPage.RssNews))'不包含'GetEnumerator'的公共定义
RssNews课程是:
public class RssNews
{
public string Title;
public string PublicationDate;
public string Description;
}
Run Code Online (Sandbox Code Playgroud)
我应该添加什么代码,以便删除错误并且代码的目的不会被编译?提前致谢!
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 …Run Code Online (Sandbox Code Playgroud)