在阅读了大约 40-50 个问题和答案(我已经尝试了很多事情)之后,所有这些都只是稍微偏离了答案,我仍然无法理解这是如何不起作用的:
IEnumerable<string> textSegs = from cd in cds
where cd.Artist.Equals("Dream Theater")
select cd.Artist;
foreach(string s in textSegs)
Console.Write("\nTrack: " + s);
//This outputs: 'Track: Dream Theater'
现在至于另一部分:
IEnumerable<string> textSegs = from seg in myXMLDoc.Descendants("name")
where ((string)seg).Equals("Dream Theater")
select (string)seg;
//This puts: exactly what I need
然后我想这会变魔术:
IEnumerable<string> textSegs = from seg in myXMLDoc.Descendants("name")
where ((string)seg).Equals(from cd in cds
where cd.Artist.Equals("Dream Theater")
select cd.Artist)
select (string)seg;
//This outputs: Everything that is inside the XMLDoc (no filter applied)
至于这段代码的格式。恐怕必须是这样的(作业)。我尝试将子查询转换为字符串,但它告诉我:
Cannot convert type 'IEnumerable<string>' to 'string'
任何帮助表示赞赏!