Created
May 31, 2014 20:26
-
-
Save Fhernd/ada988ecee68c8f0f9f0 to your computer and use it in GitHub Desktop.
Uso estándar de un delegado 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; | |
using System.IO; | |
namespace Articulos.Cap04 | |
{ | |
public delegate bool Escribir(); | |
public class SinFunc | |
{ | |
public static void Main() | |
{ | |
SalidaContenido sc = new SalidaContenido(); | |
Escribir delegadoEscribir = sc.EnviarAArchivo; | |
if (delegadoEscribir()) | |
{ | |
Console.WriteLine("La escritura fue satisfactoria."); | |
} | |
else | |
{ | |
Console.WriteLine("La escritura ha fallado."); | |
} | |
} | |
} | |
public class SalidaContenido | |
{ | |
public bool EnviarAArchivo() | |
{ | |
try | |
{ | |
StreamWriter sw = new StreamWriter("output.txt"); | |
sw.WriteLine("Blog xCSw"); | |
sw.Close(); | |
return true; | |
} | |
catch | |
{ | |
return false; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment