このコードは、Webページから情報を取得する必要があります。私の問題は、それが正面から見えず、理由を知らないということです。値が決まる前にC#変数が使用されています
ドキュメントの完成を待たずに、そのドキュメントの外に関数を作成する必要はありません。
私は大きなファイルから修正したい実際のコード:
public static string GetNews()
{
WebBrowser page = new WebBrowser();
string data = null;
page.Navigate(launcherScriptAddress);
page.DocumentCompleted += delegate {
data = page.Document.GetElementById("news").InnerText;
// can't return `data` from here
};
return data; // returns null because it doesn't wait for document to be completed
}
はあなたをしましたあなたの 'MessageBox.Show'を' delegate'関数の中に入れてみてください。 –