Complete the code to declare a generic class with a constraint that T must be a class.
public class Repository<[1]> where T : class { }
The generic type parameter is usually named T. The constraint where T : class means T must be a reference type.
Complete the code to declare a generic method with a constraint that T must have a parameterless constructor.
public void CreateInstance<[1]>() where T : new() { T obj = new T(); }new() constraint when creating a new instance.The generic type parameter T is constrained with new() to require a parameterless constructor.
Fix the error in the generic class declaration by completing the constraint so that T must inherit from BaseEntity.
public class Manager<[1]> where T : BaseEntity { }
The generic type parameter T must be the same in the declaration and the constraint. Here, where T : BaseEntity means T inherits from BaseEntity.
Fill both blanks to declare a generic method where T must be a struct and U must implement IDisposable.
public void Process<[1], U>() where [1] : struct where U : [2] { }
The first blank is the generic type parameter T constrained as a struct (value type). The second blank is the interface IDisposable that U must implement.
Fill all three blanks to declare a generic class where T must be a class, U must inherit from BaseEntity, and V must have a parameterless constructor.
public class Container<[1], [2], V> where T : class where U : BaseEntity where V : [3] { }
new() constraint for V.The generic parameters are T, U, and V. The constraints specify that T is a class, U inherits from BaseEntity, and V has a parameterless constructor (new()).