Compiler Error CS0450
'Type Parameter Name': cannot specify both a constraint class and the 'class' or 'struct' constraint
If a type parameter is constrained by the struct type constraint, it is logically contradictory for it to also be constrained by a specific class type, since struct and class are mutually exclusive categories. If a type parameter is constrained by a specific class type constraint, then it is by definition constrained by the class type constraint, and so specifying the class type constraint is redundant.
// CS0450.cs
// compile with: /t:library
public class GenericsErrors
{
public class B { }
public class G3<T> where T : struct, B { } // CS0450
// To resolve, use the following line instead:
// public class G3<T> where T : B { }
}
.NET feedback
.NET is an open source project. Select a link to provide feedback: