什麼之間的#1和#2的區別:返回值((MethodInvoker)代表{/ * ... * /};我需要做一些解釋
代碼1(編譯OK):
byte[] GetSomeBytes()
{
return (byte[])this.Invoke((MethodInvoker)delegate
{
GetBytes();
});
}
byte[] GetBytes()
{
GetBytesForm gbf = new GetBytesForm();
if(gbf.ShowDialog() == DialogResult.OK)
{
return gbf.Bytes;
}
else
return null;
}
代碼2(未遵守OK)
int GetCount()
{
return (int)this.Invoke((MethodInvoker)delegate
{
return 3;
});
}
代碼#2給我由於 'System.Windows.Forms.MethodInvoker' 返回void,返回關鍵字一定不能跟一個對象表達式。
我該如何解決?爲什麼(做)編譯器認爲代碼#1是正確的?
我們能有更多一點的代碼。 「this」指的是什麼類型? – 2010-06-25 12:35:07
@Matthew,Windows窗體。 – 2010-06-25 12:41:57