Complete the code to declare an interface with covariance using the out keyword.
interface IProducer<[1]> { [1] Produce(); }
The out keyword enables covariance in generic interfaces, allowing a more derived type to be returned.
Complete the code to assign a more derived type to a covariant interface variable.
IProducer<Animal> animalProducer = new Producer<[1]>();Because of covariance, you can assign Producer<Dog> to IProducer<Animal> since Dog inherits from Animal.
Fix the error in the interface declaration to enable covariance.
interface IProducer<[1]> { T Produce(); }The out keyword must be used to declare covariance in the generic type parameter.
Fill both blanks to declare a covariant interface and a method that returns the generic type.
interface IProducer<[1]> { [2] Produce(); }
The interface uses out T for covariance, and the method returns T.
Fill all three blanks to declare a covariant interface, a method returning the generic type, and assign a derived type instance to a base type variable.
interface IProducer<[1]> { [2] Produce(); } IProducer<Animal> producer = new Producer<[3]>();
The interface uses out T for covariance, the method returns T, and Producer<Dog> can be assigned to IProducer<Animal> because of covariance.