0

我試圖解析一些簡單的XML這樣的時候沒有發現:的WinRT:「其中」解析XML

XElement thisLevel = from l in xmlElements.Descendants("Level") 
         where l.Element("LevelNum") == thisLevel 
         select l; 

但我得到一個錯誤的「水平」的說法:

未能進行查找源類型爲 'System.Collections.Generic.IEnumerable'的查詢模式的實現。 '找不到'。您是否缺少'System.Linq'的參考或使用指令 ?

奇怪的是我能搶的後代:

var levels = xmlElements.Descendants("Level"); 

這一工程,但我似乎沒有能夠在那裏就可以了。

+1

您是否在錯誤消息中提供了「Sytstem.Linq」的引用和使用指令? – ChrisF 2013-03-02 12:42:28

+0

糟糕。我錯誤地認爲使用System.Xml.Linq會包含linq。我的問題很糟糕。 – micahhoover 2013-03-02 12:49:21

回答

2

正如ChrisF提到的,這些using語句都是必需的:

using System.Xml.Linq; 
using System.Linq; // this one was missing 

我原以爲System.Xml.Linq的將涵蓋所有的一切LINQ相關。

謝謝,ChrisF!