Sends for the fellow dear visitors:welcome to dongpad!


 Welcome to DongPad!

 msn


无法将 匿名方法 转换为类型“System.Delegate”,因为它不是委托类型

The problem the user is seeing is that the Thread ctor accepts a specific delegate -- the ThreadStart delegate. The C# compiler will check and make sure your anonymous method matches the signature of the ThreadStart delegate and, if so, produces the proper code under-the-covers to create the ThreadStart delegate for you. But Control.Invoke is typed as accepting a "Delegate". This means it can accept any delegate-derived type. The example above shows an anonymous method that has a void return type and takes no parameters. It's possible to have a number of delegate-derived types that match that signature (such as MethodInvoker and ThreadStart -- just as an example). Which specific delegate should the C# compiler use? There's no way for it to infer the exact delegate type so the compiler complains with an error.

评论: 1 | 引用: 0 | 查看次数: 1174 | 返回顶部
Jack [2011-2-28 17:12:21 ]
Control.Invoke 方法参数为 Delegate,所以该方法可以接收所有委托类型,如果我们调用该方法传递的是匿名方法,将导致编译器无法确认传入的参数究竟是什么类型的委托,以至于出现该错误!
发表评论
昵 称:    
验证码:   
 
内 容:
选 项:  
 
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 500 字 | UBB代码 开启 | [img]标签 开启