Compiler Error CS0456
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.
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
}
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: