Share via


컴파일러 오류 CS0425

업데이트: 2007년 11월

오류 메시지

'method' 메서드의 'type parameter' 형식 매개 변수에 대한 제약 조건이 'method' 인터페이스 메서드의 'type parameter' 형식 매개 변수에 대한 제약 조건과 일치해야 합니다. 명시적 인터페이스 구현을 대신 사용하십시오.
The constraints for type parameter 'type parameter' of method 'method' must match the constraints for type parameter 'type parameter' of interface method 'method'. Consider using an explicit interface implementation instead.

이 오류는 파생 클래스에서 가상 제네릭 메서드가 재정의되고 파생 클래스의 메서드에 대한 제약 조건이 기본 클래스의 메서드에 대한 제약 조건과 일치하지 않는 경우에 발생합니다. 이 오류가 발생하지 않도록 하려면 두 선언에서 where 절을 동일하게 만들거나 인터페이스를 명시적으로 구현하십시오.

예제

다음 예제에서는 CS0425 오류가 발생하는 경우를 보여 줍니다.

// CS0425.cs

class C1
{
}

class C2
{
}

interface IBase
{
    void F<ItemType>(ItemType item) where ItemType : C1;
}

class Derived : IBase
{
    public void F<ItemType>(ItemType item) where ItemType : C2  // CS0425
    {
    }
}

class CMain
{
    public static void Main()
    {
    }
}

제약 조건 집합의 의미가 동일하다면 제약 조건의 리터럴이 일치하지 않아도 됩니다. 예를 들어, 다음은 올바른 경우입니다.

// CS0425b.cs

interface J<Z>
{
}

interface I<S>
{
    void F<T>(S s, T t) where T: J<S>, J<int>;
}

class C : I<int>
{
    public void F<X>(int s, X x) where X : J<int>
    {
    }

    public static void Main()
    {
    }
}