zoukankan      html  css  js  c++  java
  • C#的Compiler Error CS1660

    原文地址:http://stackoverflow.com/questions/3926500/base-invoke-with-delegates

    问题:

    I am invoking a delegate and I'm not very informed about how it works and I have compilation errors because of it (Compiler Error CS1660). This is the code I have for it:




    原因:

    this is because Invoke accepts Delegate which is not (sic!) a delegate type as far as the C# compiler is concerned. A delegate type should define a call signature, while Delegate does not and is just a common ancestor. The expression delegate { ... } has type... try to guess... anonymous delegate(if it was a method it would be method group). They are not delegate types either! But they can be implicitly converted to a delegate type that has a matching signature. And delegate types can be implicitly converted to Delegate.

    Action is: public delegate void Action();

    simply, chains:

    • Anonymous method → Delegate: no conversion exists
    • Anonymous method → Action: implicit conversion if signature matches
    • Action → Delegate: implicit conversion (Action is descendant of Delegate)

    Combine them:

    • Anonymous method → Action → Delegate: it works!
    尝试以下代码即可解决:





  • 相关阅读:
    关于博客园各项工具的使用
    Java常用的7大排序算法汇总
    Java 基本数据类型(新手必看资料)
    学习Java,还需要学好哪些知识
    JavaSE基础知识总结
    python2.7.11安装pygame包
    phpstorm打开项目目录时,出现一直在扫描文件
    laravel 通过npm搭建前端资源的注意事项
    基于laravel5.2进行rabbitmq队列服务发送接收信息
    在centos7中安装composer
  • 原文地址:https://www.cnblogs.com/hold/p/2286778.html
Copyright © 2011-2022 走看看