Share via


컴파일러 오류 CS0456

업데이트: 2007년 11월

오류 메시지

형식 매개 변수 'Type Parameter Name 1'에는 'struct' 제약 조건이 있으므로 'Type Parameter Name 1'은(는) 'Type Parameter Name 2'에 대한 제약 조건으로 사용할 수 없습니다.
Type parameter 'Type Parameter Name 1' has the 'struct' constraint so 'Type Parameter Name 1' cannot be used as a constraint for 'Type Parameter Name 2'

값 형식 제약 조건이 암시적으로 sealed되었으므로 두 번째 형식 매개 변수에서 제약 조건으로 사용할 수 없습니다. 값 형식을 재정의할 수 없기 때문입니다. 이 오류를 해결하려면 첫 번째 형식 매개 변수를 간접적으로 사용하는 대신 두 번째 형식 매개 변수에 값 형식 제약 조건을 직접 사용합니다.

예제

다음 샘플에서는 CS0456 오류가 발생하는 경우를 보여 줍니다.

// CS0456.cs
// compile with: /target:library
public class GenericsErrors
{
   public class G5<T> where T : struct
   {
      public class N<U> where U : T {}   // CS0456
      public class N2<U> where U : struct {}   // OK
   }
}