Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created May 31, 2014 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/ada988ecee68c8f0f9f0 to your computer and use it in GitHub Desktop.
Save Fhernd/ada988ecee68c8f0f9f0 to your computer and use it in GitHub Desktop.
Uso estándar de un delegado en C#.
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