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.
The 'class'
, 'struct'
, 'unmanaged'
, 'notnull'
, and 'default'
constraints cannot be combined or duplicated, and must be specified first in the constraints list.
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
public interface I {} // Made public to avoid CS0703
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 {}
}