Export (0) Print
Expand All
Expand Minimize

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.

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 {}
}

Community Additions

ADD
Show:
© 2014 Microsoft