Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement