Share via


컴파일러 경고(수준 1) CS1956

업데이트: 2007년 11월

오류 메시지

'name' 멤버는 'type' 형식의 인터페이스 멤버 'name'을(를) 구현합니다. 런타임에 인터페이스 멤버에 일치하는 여러 항목이 있습니다. 호출되는 메서드는 구현에 따라 다릅니다.
Member 'name' implements interface member 'name' in type 'type'. There are multiple matches for the interface member at run-time. It is implementation dependent which method will be called.

이 경고는 특정 매개 변수가 ref 또는 out인지에 따라서만 두 인터페이스 메서드가 구분되는 경우에 발생합니다. 실제로 런타임에 두 메서드 중 어느 것이 호출될지 명확하지 않거나 보장할 수 없기 때문에 이 경고가 발생하지 않도록 코드를 변경하는 것이 좋습니다.

C#에서는 out과 ref를 구분하지만 CRL에서는 이 두 메서드를 동일한 것으로 인식합니다. 이 때문에 CLR에서는 인터페이스를 구현할 때 두 메서드 중 하나를 임의로 선택합니다.

이 경고를 방지하려면

  • 컴파일러에서 구분할 수 있도록 두 메서드를 차별화합니다. 예를 들어 이름을 다르게 지정하거나 두 메서드 중 하나에 매개 변수를 하나 더 추가할 수 있습니다.

예제

다음 코드에서는 Base의 두 Test 메서드가 첫 번째 매개 변수의 ref/out 한정자만 다르기 때문에 CS1056 오류가 발생합니다.

// cs1956.cs
class Base<T, S>
{
    // This is the method that should be called.
    public virtual int Test(out T x) // CS1956
    {
        x = default(T);
        return 0;
    }

    // This is the "last" method and is the one that ends up being called
    public virtual int Test(ref S x)
    {
        return 1;
    }
}

interface IFace
{
    int Test(out int x);
}

class Derived : Base<int, int>, IFace
{
    static int Main()
    {
        IFace x = new Derived();
        int y;
        return x.Test(out y);
    }
}