Created
May 30, 2014 20:25
-
-
Save Fhernd/cbdd833a277f694a9c6e to your computer and use it in GitHub Desktop.
Demostración de uso de métodos anónimos 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
using System; | |
namespace Articulos.Cap04 | |
{ | |
// Declaración de delegado: | |
internal delegate void Delegado(int valor); | |
internal class Aplicacion | |
{ | |
public static void Main() | |
{ | |
// Definamos una instancia de `Delegado`, y | |
// le asignamos un método anónimo: | |
Delegado del = delegate(int valor) | |
{ | |
Console.WriteLine("El contenido de `valor` es: {0}", valor.ToString()); | |
}; | |
Console.WriteLine(); | |
// Invocación al método anónimo usando como | |
// intermediario el delegado: | |
del(99); | |
Console.WriteLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment