Created
June 3, 2014 23:11
-
-
Save Fhernd/c08d5d657eddf198fb6d to your computer and use it in GitHub Desktop.
Demostración del uso del operador is en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment