私はLINQを学んでいて、select
句に関連するこの例を試していました。
var q = from c in xmlDoc.Descendants("site").Where(tech => tech.Attribute("technical").Value == "true")
.Select(n => new { SiteName = n.Element("name").Value});
上記のクエリは私にエラーを与えています:
The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
上記の構文で何が間違っていますか?
上記とは別に、selected
オプションを変換する必要がありますToDictionary
。LINQ を介して同じクエリでどのように実行できますか?
私が頭に浮かんだ 3 番目の質問は、同じクエリを記述するための異なる構文についてでした (e: 以下の 2 番目のメソッドの記述例)。優先される構文とその理由は?
from c in xmlDoc.Descendants
where c.Attriubute("technical").Value == "true"
select c.Element("site").Value;