相关疑难解决方法(0)

当派生类型为1作为参数传递时,双向隐式可转换类型的重载之间的模糊调用

(试图找到一个总结问题的标题可能是一项非常艰巨的任务!)

我有以下类与一些重载方法,产生一个调用歧义编译器错误:

public class MyClass
{
    public static void OverloadedMethod(MyClass l) { }
    public static void OverloadedMethod(MyCastableClass l) { }

    //Try commenting this out separately from the next implicit operator. 
    //Comment out the resulting offending casts in Test() as well.
    public static implicit operator MyCastableClass(MyClass l)
    {
        return new MyCastableClass();
    }

    //Try commenting this out separately from the previous implicit operator.
    //Comment out the resulting offending casts in Test() as well.
    public static implicit operator MyClass(MyCastableClass l)
    {
        return new …
Run Code Online (Sandbox Code Playgroud)

c# overloading ambiguous implicit-cast

6
推荐指数
1
解决办法
785
查看次数

标签 统计

ambiguous ×1

c# ×1

implicit-cast ×1

overloading ×1