Compiler Error CS0449
The 'class' or 'struct' constraint must come before any other constraints
The constraints on the type parameter of a generic type or method must occur in a specific order: class
or struct
must be first, if present, then any interface constraints, and finally any constructor constraints. This error is caused by the class
or struct
constraint not appearing first. To resolve this error, reorder the constraint clauses.
Example
The following sample generates CS0449.
// CS0449.cs
// compile with: /target:library
interface I {}
public class C4
{
public void F1<T>() where T : class, struct, I {} // CS0449
public void F2<T>() where T : I, struct {} // CS0449
public void F3<T>() where T : I, class {} // CS0449
// OK
public void F4<T>() where T : class {}
public void F5<T>() where T : struct {}
public void F6<T>() where T : I {}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for