2011-11-10 8 views
-1

私はコンソールアプリケーションでHtmlAgilityPackを使用することですが、WPFアプリケーションにしようとしたとき、私はいつもこのラインdocument.DocumentNode.Descendants()でこのエラーを取得するために働いていない:がHtmlAgilityPack私のWPFプロジェクト

Could not find an implementation of the query pattern for source type 'System.Collections.Generic.IEnumerable<HtmlAgilityPack.HtmlNode>'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? 

これはコードです:

public partial class Window1 : Window 
    { 
     public Window1() 
     { 
      var webget = new HtmlWeb(); 

      var document = webget.Load("http://google.com"); 

      var p = from program in document.DocumentNode.Descendants() 
        where program.Name == "a" 
        select program.InnerText; 

      InitializeComponent(); 
     } 
    } 

なぜ誰かが私にそのエラーが表示されますか?

ありがとうございました。

+1

しかし、そのソースファイルに 'using System.Linq'がありますか? – ordag

+0

ダムそれ、私はそんなに、答えとして投稿してください、私は受け入れ、感謝します。 – Kobe

答えて

3

追加:

using System.Linq; 

を、ファイルの先頭近くにある既存のusingステートメントに追加します。

2

追加名前空間宣言System.Linq

using System.Linq; 
1

あなたはこのコードを記述するための名前空間を追加する必要があります...あなたはusing System.Linq;にこの名前空間を追加する必要がありますので

var p = from program in document.DocumentNode.Descendants() 
       where program.Name == "a" 
       select program.InnerText; 

この

は、LINQを使用して書かれた

関連する問題