English 中文(简体)
体力和杂质参数超载方法之间的重叠
原标题:Ambiguity between method overloads with string and EventHandler parameters

I m在超载方法方面遇到一些困难。 我的签名就是这样:

void Register(object source, EventHandler mapped_handler)
void Register(object source, string mapped_property)

我不想这样说:

Register(someObject, (s, e) => { ... });

2008年视觉演播室给我error CS1503: 说明2:不能从系统转换。 页: 1

我失踪了什么? 我并不真正确定问题在哪里。 我有其他非超载方法,我可以通过<代码>EventHandler lambdas无问题。

最佳回答

感谢所有答复......表明,这是我方法声明中的一个问题。 我在方法上签字时有第1参数的类型被指明是错误的。 我把这个问题留给像我这样sil误的其他人。

问题回答

这应该绝对是严厉的。 简短但完整的例子:

using System;

public class Test
{
    static void Main(string[] args)
    {
        object o = new object();
        Register(o, (s, e) => {});
    }

    static void Register(object source, EventHandler handler)
    {
        Console.WriteLine("Handler");
    }

    static void Register(object source, string text)
    {
        Console.WriteLine("Text");
    }
}

如果你能以同样简短但完整的例子(doesn t)更新你的问题,我们就有可能进一步帮助。 (我的猜测是,实际上正在举一个简短但完整的例子,你发现问题。)

您的错误信息明确谈到<代码>EventHandler,这在一定程度上令人怀疑——因为你的论点的类型isn t EventHandler,它只是一个可以tverted的Mlambda表述。 你们是否相信这一错误出现在电话线上?

你们需要做:

Register(someObject, new EventHandler((s,e)=>{...}));




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...