Lan*_*ins 0 c# linq ienumerable types
我正在研究linq方法,似乎无法获得与方法签名匹配的返回类型.任何指导都将非常感谢.
谢谢!
private static IEnumerable<KeyValuePair<string, string>> RunQuery(XDocument doc)
{
var data = from b in doc.Descendants("Company")
where b.Attribute("name").Value == "CompanyA"
from y in b.Descendants("Shirt")
from z in y.Descendants("Size")
select new
{
color = y.Attribute("id").Value,
price = z.Value
};
return data;
}
Run Code Online (Sandbox Code Playgroud)
你必须创建KeyValuePairs.
...
select new KeyValuePair(y.Attribute("id").Value, z.Value)
Run Code Online (Sandbox Code Playgroud)