namespace VariantStack; class Program { static void Main(string[] args) { // Covariance var carStack = new Stack(); carStack.Push(new Car()); carStack.Push(new Car()); IPoppable carPoppable = carStack; WashVehicles(carPoppable); void WashVehicles(IPoppable vehicles) { while (vehicles.Count > 0) { Vehicle vehicle = vehicles.Pop(); Console.WriteLine($"Washing {vehicle}"); } } // Contravariance var vehiclesStack = new Stack(); vehiclesStack.Push(new Car()); vehiclesStack.Push(new Bike()); IPushable vehiclePushable = vehiclesStack; DeliverCars(vehiclePushable, 2); void DeliverCars(IPushable cars, int count) { for (int i = 0; i < count; i++) { Console.WriteLine("Adding car to IPushable"); cars.Push(new Car()); } } } }