#1和#2有什么区别:
代码1(编译成功):
代码1(编译成功):
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(未通过编译)
int GetCount()
{
return (int)this.Invoke((MethodInvoker)delegate
{
return 3;
});
}
代码#2给我返回了"由于'System.Windows.Forms.MethodInvoker'返回void,因此return关键字后面不能跟随对象表达式"的错误信息。
我该如何修复它?为什么编译器认为代码#1是正确的?