<small id='7Wnnx'></small><noframes id='7Wnnx'>

  1. <legend id='7Wnnx'><style id='7Wnnx'><dir id='7Wnnx'><q id='7Wnnx'></q></dir></style></legend>

    <tfoot id='7Wnnx'></tfoot>
    <i id='7Wnnx'><tr id='7Wnnx'><dt id='7Wnnx'><q id='7Wnnx'><span id='7Wnnx'><b id='7Wnnx'><form id='7Wnnx'><ins id='7Wnnx'></ins><ul id='7Wnnx'></ul><sub id='7Wnnx'></sub></form><legend id='7Wnnx'></legend><bdo id='7Wnnx'><pre id='7Wnnx'><center id='7Wnnx'></center></pre></bdo></b><th id='7Wnnx'></th></span></q></dt></tr></i><div id='7Wnnx'><tfoot id='7Wnnx'></tfoot><dl id='7Wnnx'><fieldset id='7Wnnx'></fieldset></dl></div>
        <bdo id='7Wnnx'></bdo><ul id='7Wnnx'></ul>
    1. 我可以定义 2 个名称相同但参数不同的委托吗?

      Can I define 2 delegates with the same name but different parameters?(我可以定义 2 个名称相同但参数不同的委托吗?)
        <tbody id='iOytT'></tbody>

        1. <legend id='iOytT'><style id='iOytT'><dir id='iOytT'><q id='iOytT'></q></dir></style></legend>

                <bdo id='iOytT'></bdo><ul id='iOytT'></ul>
                <tfoot id='iOytT'></tfoot>
              • <small id='iOytT'></small><noframes id='iOytT'>

                <i id='iOytT'><tr id='iOytT'><dt id='iOytT'><q id='iOytT'><span id='iOytT'><b id='iOytT'><form id='iOytT'><ins id='iOytT'></ins><ul id='iOytT'></ul><sub id='iOytT'></sub></form><legend id='iOytT'></legend><bdo id='iOytT'><pre id='iOytT'><center id='iOytT'></center></pre></bdo></b><th id='iOytT'></th></span></q></dt></tr></i><div id='iOytT'><tfoot id='iOytT'></tfoot><dl id='iOytT'><fieldset id='iOytT'></fieldset></dl></div>
                本文介绍了我可以定义 2 个名称相同但参数不同的委托吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我试图在 Int32IntPtr 之间定义一个委托覆盖.为什么以下重载是非法的?

                I tried to define a delegate override between Int32 and IntPtr. Why are the following overloads illegal?

                public delegate int EnumWindowsCallback (System.IntPtr hWnd, int lParam);
                
                public delegate int EnumWindowsCallback (System.IntPtr hWnd, System.IntPtr lParam);
                

                这看起来很奇怪.它们都是结构,但不同,并从不同的接口实现.

                That looks pretty strange. They are both structs but are different and implement from different interfaces.

                想一想,我以前从未尝试过重载委托.这是否合法,如果是,为什么?

                Come to think of it, I have never tried to overload a delegate before. Is it even legal, and if so, why?

                更新:在查看了答案和更多 SO 帖子后,我感到困惑的是,即使使用不同数量的参数也无法声明代表.我仍然想知道为什么不能在运行时解决这个问题.

                UPDATE: After going through the answers and some more SO posts, I was baffled that delegates cannot be declared even with a varying number of parameters. I am still wondering why this cannot be resolved at runtime.

                推荐答案

                想一想,我以前从未尝试过重载委托.这是否合法,如果是,为什么?

                Come to think of it, I have never tried to overload a delegate before. Is it even legal, and if so, why?

                不,这是不合法的.您当前正在声明两个具有相同完全限定名称的类型.

                No, it's not legal. You're currently declaring two types with the same fully-qualified name.

                在类型方面看起来唯一有点像重载的是,如果您声明了两个泛型类型参数数量不同的类型.比如Action<T>Action<T1, T2>等.这里的delegate的规则和其他类型的规则没有区别.

                The only thing that looks a bit like overloading when it comes to types is if you declare two types which differ in the number of generic type parameters. For example, Action<T>, Action<T1, T2> etc. The rules for delegates are no different than the rules for other types here.

                因此,要么您需要声明一个泛型委托(并使用不同的类型参数),要么使用两个不同的类型名称.

                So either you need to declare one generic delegate (and use different type arguments), or use two different type names.

                这篇关于我可以定义 2 个名称相同但参数不同的委托吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                • <i id='yVsII'><tr id='yVsII'><dt id='yVsII'><q id='yVsII'><span id='yVsII'><b id='yVsII'><form id='yVsII'><ins id='yVsII'></ins><ul id='yVsII'></ul><sub id='yVsII'></sub></form><legend id='yVsII'></legend><bdo id='yVsII'><pre id='yVsII'><center id='yVsII'></center></pre></bdo></b><th id='yVsII'></th></span></q></dt></tr></i><div id='yVsII'><tfoot id='yVsII'></tfoot><dl id='yVsII'><fieldset id='yVsII'></fieldset></dl></div>

                  • <bdo id='yVsII'></bdo><ul id='yVsII'></ul>

                        <tbody id='yVsII'></tbody>
                      1. <legend id='yVsII'><style id='yVsII'><dir id='yVsII'><q id='yVsII'></q></dir></style></legend>
                      2. <small id='yVsII'></small><noframes id='yVsII'>

                          <tfoot id='yVsII'></tfoot>