共用方式為


編譯器錯誤 CS0473

更新:2007 年 11 月

錯誤訊息

明確介面實作 'method name' 符合多個介面成員。實際選擇的介面成員為與實作相關。請考慮使用非明確實作代替。

在某些情況下,泛型方法取得的簽章 (Signature) 會與非泛型方法相同。問題是出在 Common Language Infrastructure (CLI) 中繼資料 (Metadata) 系統中沒有方式可以清楚地陳述哪個方法繫結至哪個位置。完全是根據 CLI 來進行這項判斷。

注意事項:

Visual Studio 2005 中不會引發這個錯誤的位置,在 Visual Studio 2008 中則會引發這個錯誤。

若要更正這個錯誤

  • 去除明確實作 (Implementation),並只讓隱含實作 public int TestMethod(int) 實作這兩種介面方法。

範例

下列程式碼會產生 CS0473:

// cs0473.cs
public interface ITest<T>
{
    int TestMethod(int i);
    int TestMethod(T i);
}

public class ImplementingClass : ITest<int>
{
    int ITest<int>.TestMethod(int i) // CS0473
    {
        return i + 1;
    }

    public int TestMethod(int i)
    {
        return i - 1;
    }
}

class T
{
    static int Main()
    {
        ImplementingClass a = new ImplementingClass();
        if (a.TestMethod(0) != -1)
            return -1;

        ITest<int> i_a = a;
        System.Console.WriteLine(i_a.TestMethod(0).ToString());
        if (i_a.TestMethod(0) != 1)
            return -1;

        return 0;
    }
}

請參閱

其他資源

程式碼撰寫的神奇冒險