// ===++===
//
// OrtizOL
//
// ===--===
/*============================================================
//
// Clase: ContraVarianza.cs
//
// Propósito: Demostración de la covarianza.
//
============================================================*/
namespace Articulos.Cap03
{
internal class Animal { };
internal class Oso : Animal { };
internal interface IPushable<in T>
{
void Push(T obj);
}
internal class Pila<T> : IPushable<T>
{
public void Push(T obj) { }
}
internal class ContraVarianza
{
public static void Main()
{
IPushable<Animal> animales = new Pila<Animal>();
IPushable<Oso> osos = animales;
osos.Push( new Oso() );
}
}
}
Ly8gPT09Kys9PT0KLy8KLy8gICAgT3J0aXpPTAovLwovLyA9PT0tLT09PQovKj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQovLwovLyBDbGFzZTogQ29udHJhVmFyaWFuemEuY3MKLy8KLy8gUHJvcMOzc2l0bzogRGVtb3N0cmFjacOzbiBkZSBsYSBjb3ZhcmlhbnphLgovLwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0qLwoKbmFtZXNwYWNlIEFydGljdWxvcy5DYXAwMwp7CiAgICBpbnRlcm5hbCBjbGFzcyBBbmltYWwgeyB9OwogICAgaW50ZXJuYWwgY2xhc3MgT3NvIDogQW5pbWFsIHsgfTsKICAgIAogICAgaW50ZXJuYWwgaW50ZXJmYWNlIElQdXNoYWJsZTxpbiBUPgogICAgewogICAgICAgIHZvaWQgUHVzaChUIG9iaik7CiAgICB9CiAgICAKICAgIGludGVybmFsIGNsYXNzIFBpbGE8VD4gOiBJUHVzaGFibGU8VD4gCiAgICB7CiAgICAgICAgcHVibGljIHZvaWQgUHVzaChUIG9iaikgeyB9CiAgICB9CiAgICAKICAgIGludGVybmFsIGNsYXNzIENvbnRyYVZhcmlhbnphCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgSVB1c2hhYmxlPEFuaW1hbD4gYW5pbWFsZXMgPSBuZXcgUGlsYTxBbmltYWw+KCk7CiAgICAgICAgICAgIElQdXNoYWJsZTxPc28+IG9zb3MgPSBhbmltYWxlczsKICAgICAgICAgICAgb3Nvcy5QdXNoKCBuZXcgT3NvKCkgKTsKICAgICAgICB9CiAgICB9Cn0=