Compiler Error CS0314
The type 'type1' cannot be used as type parameter 'name' in the generic type or method 'name'. There is no boxing conversion or type parameter conversion from 'type1' to 'type2'.
When a generic type uses a type parameter that is constrained, the new class must also satisfy those same constraints.
To correct this error
- In the example that follows, add
where T : ClassConstraint
to classB
.
Example
The following code generates CS0314:
// cs0314.cs
// Compile with: /target:library
public class ClassConstraint { }
public class A<T> where T : ClassConstraint
{ }
public class B<T> : A<T> //CS0314
{ }
// Try using this instead.
public class C<T> : A<T> where T : ClassConstraint
{ }
See also
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