Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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'
Value type constraints are implicitly sealed so those constraints cannot be used as constraints on a second type parameter. This is because value types cannot be overridden. To resolve this error, put a value type constraint directly on the second type parameter, instead of doing so indirectly by means of the first type parameter.
Example
The following sample generates 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
}
}