我正在學習LINQ並嘗試使用與select
子句相關的此示例。select子句中表達式的類型不正確。在「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'.
什麼是錯的INT上述語法?
除了上述,我必須轉換selected
選項ToDictionary
。如何通過LINQ在同一個查詢中完成?
我在腦海裏想的第三個問題是關於編寫同一個查詢的不同語法(e:下面的第二個寫方法)。什麼語法是首選,爲什麼?
from c in xmlDoc.Descendants
where c.Attriubute("technical").Value == "true"
select c.Element("site").Value;
做了第二個查詢工作,或者它也給你錯誤? –
不太瞭解錯誤,您可以發佈您的示例XML嗎? – Habib
第二個查詢工作 – user1372448