Quantcast
Channel: 2,000 Things You Should Know About C# » Type Parameters
Viewing all articles
Browse latest Browse all 7

#548 – No More Than One Class for a Type Parameter Constraint

$
0
0

When specifying constraints for a type parameter in a generic class, you can specify at most one class as a constraint, but  you can specify one or more interfaces.  If one of the constraints is a class type, it must come first.

// Type must be castable to DogToy and must implement
//   IEdible and IBuryable
public class Dog<TFavToy>
    where TFavToy : DogToy, IEdible, IBuryable

Filed under: Classes Tagged: C#, Classes, Constraint, Generic Classes, Type Parameters, Where

Viewing all articles
Browse latest Browse all 7

Trending Articles