Complete the code to declare a contravariant interface using the in keyword.
public interface IProcessor<[1] T> { void Process(T item); }out instead of in for contravariance.ref or var which are invalid here.in keyword declares contravariance in generic interfaces, allowing the type parameter to be used only as input.Complete the code to assign a contravariant interface reference correctly.
IProcessor<object> objProcessor = new Processor<string>();
IProcessor<string> strProcessor = [1];new Processor directly to IProcessor which is invalid.IProcessor can be assigned to IProcessor reference.Fix the error in the method parameter type to support contravariance.
public void Execute(IProcessor<[1]> processor) { processor.Process("test"); }
string restricts the method to only that type, breaking contravariance.int or dynamic without context.object allows passing processors of more derived types due to contravariance.Fill both blanks to declare a contravariant interface and implement it correctly.
public interface IHandler<[1] T> { void Handle(T item); } public class StringHandler : IHandler<[2]> { public void Handle(string item) { } }
out instead of in for contravariance.in for contravariance, and the class implements it for string type.Fill all three blanks to create a contravariant delegate and use it correctly.
public delegate void Processor<[1] T>(T item); Processor<[2]> stringProcessor = item => Console.WriteLine(item); Processor<[3]> objectProcessor = stringProcessor;
out instead of in for contravariance in delegates.in keyword; a Processor can be assigned to Processor due to contravariance.