Created
May 31, 2014 01:50
-
-
Save Fhernd/cf5b4b1a323e64d65e96 to your computer and use it in GitHub Desktop.
Demostración de covarianza con delegados 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
namespace Articulos.Cap04 | |
{ | |
internal class Mamifero { } | |
internal class Perro : Mamifero { } | |
internal class Aplicacion | |
{ | |
public static void Main() | |
{ | |
Delegado delegadoMamifero = MetodoMamifero; | |
// A través de la covarianza podemos realizar | |
// la siguiente asignación: | |
Delegado delegadoPerro = MetodoPerro; | |
} | |
// Delegado con tipo de retorno Mamifero, | |
// la cual es la clase base de la jerarquía | |
// de herencia: | |
public delegate Mamifero Delegado(); | |
public static Mamifero MetodoMamifero() | |
{ | |
return null; | |
} | |
public static Perro MetodoPerro() | |
{ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment