从 API 下载数据后,我尝试使用数据。我的代码示例:
private int id;
public MainPage()
{
InitializeComponent();
SomeFunction();
}
public void SomeFunction()
{
DownloadFromAPI("url to api");
MessageBox.Show(id.ToString()); //<< Returns 0
}
public void DownloadFromAPI(DownloadStringCompletedEventArgs url)
{
//code to retrieve data (singel id)
id = Int16.Parse(data);
MessageBox.Show(id.ToString()); //<< Returns the correct number, like 14
test();
}
private void test()
{
MessageBox.Show(id.ToString()); //<< Even Returns the correct number 14
}
完成后如何加载id信息DownloadFromAPI("url to api");
。所以我得到正确的数字(14)而不是0?