这只是代码的一部分
向下几行,我试图将Int转换为double。但是double是一个数组的事实让它很难......
我需要包含“i”,就像我在上一个函数中所做的那样,但是它不起作用,我得到以下错误;
'webKoordx_OpenReadComplete'没有重载符合委托'System.Net.OpenReadCompletedEventHandler'
如果你知道任何解决方案,或者能够看到我错过的东西,请帮助我!
private void getKoord(int i)
{
string stringKoX = "http://media.vgy.se/kristoferpk/spots/" + i + "/koordinatx.html";
string stringKoY = "http://media.vgy.se/kristoferpk/spots/" + i + "/koordinaty.html";
var webKoordx = new WebClient();
webKoordx.OpenReadAsync(new Uri(stringKoX));
webKoordx.OpenReadCompleted += new OpenReadCompletedEventHandler(webKoordx_OpenReadComplete);
var webKoordy = new WebClient();
webKoordy.OpenReadAsync(new Uri(stringKoY));
webKoordy.OpenReadCompleted += new OpenReadCompletedEventHandler(webKoordy_OpenReadComplete);
}
void webKoordx_OpenReadComplete(object sender, OpenReadCompletedEventArgs e, int i)//<<-----
{
try
{
using (var reader = new StreamReader(e.Result))
{
koordx = reader.ReadToEnd();
koordx_d[i] = Convert.ToDouble(koordx);
}
}
catch
{
MessageBox.Show("Kan ej ansluta");
MessageBox.Show("Kontrollera din anslutning");
}
}
void webKoordy_OpenReadComplete(object sender, OpenReadCompletedEventArgs e)//<<-----
{
try
{
using (var reader = new StreamReader(e.Result))
{
koordy = reader.ReadToEnd();
koordy_d[i] = Convert.ToDouble(koordy);
}
}
catch
{
MessageBox.Show("Kan ej ansluta");
MessageBox.Show("Kontrollera din anslutning");
}
}
答案 0 :(得分:1)
您无法将额外信息传递给类似的事件处理程序。
相反,您可以添加一个处理事件的lambda表达式,并从closure传递您的额外信息:
webKoordx.OpenReadCompleted += (sender, e) => MyMethod(e.Result, i);