using System;
namespace Recetas.Cap03
{
internal class A { }
internal class B { }
internal class C : B { }
internal class Aplicacion
{
public static void Main()
{
A a = new A();
B b = new B();
C c = new C();
Console.WriteLine();
ComprobarObjetos(a);
ComprobarObjetos(b);
ComprobarObjetos(c);
ComprobarObjetos("Blog xCSw");
Console.WriteLine();
}
public static void ComprobarObjetos(object o)
{
if ( o is A)
{
Console.WriteLine("El objeto `o` es de clase `A`.");
}
else if (o is B)
{
Console.WriteLine("El objeto `o` es de clase `B`.");
}
else
{
Console.WriteLine("El objeto `o` no corresponde con ninguna de las clases.");
}
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ2FwMDMKewogICAgaW50ZXJuYWwgY2xhc3MgQSB7IH0KICAgIGludGVybmFsIGNsYXNzIEIgeyB9CiAgICBpbnRlcm5hbCBjbGFzcyBDIDogQiB7IH0KICAgIAogICAgaW50ZXJuYWwgY2xhc3MgQXBsaWNhY2lvbgogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIEEgYSA9IG5ldyBBKCk7CiAgICAgICAgICAgIEIgYiA9IG5ldyBCKCk7CiAgICAgICAgICAgIEMgYyA9IG5ldyBDKCk7CiAgICAgICAgICAgIAogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgICAgICBDb21wcm9iYXJPYmpldG9zKGEpOwogICAgICAgICAgICBDb21wcm9iYXJPYmpldG9zKGIpOwogICAgICAgICAgICBDb21wcm9iYXJPYmpldG9zKGMpOwogICAgICAgICAgICAKICAgICAgICAgICAgQ29tcHJvYmFyT2JqZXRvcygiQmxvZyB4Q1N3Iik7CiAgICAgICAgICAgIAogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgQ29tcHJvYmFyT2JqZXRvcyhvYmplY3QgbykKICAgICAgICB7ICAgIAogICAgICAgICAgICBpZiAoIG8gaXMgQSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkVsIG9iamV0byBgb2AgZXMgZGUgY2xhc2UgYEFgLiIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYgKG8gaXMgQikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkVsIG9iamV0byBgb2AgZXMgZGUgY2xhc2UgYEJgLiIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkVsIG9iamV0byBgb2Agbm8gY29ycmVzcG9uZGUgY29uIG5pbmd1bmEgZGUgbGFzIGNsYXNlcy4iKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQ==