Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 10, 2014 16:58
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/206e1dfb3dc962b6c8ca to your computer and use it in GitHub Desktop.
Save Fhernd/206e1dfb3dc962b6c8ca to your computer and use it in GitHub Desktop.
Demostración del uso del delegado genérico Func<TResult> con expresiones lambda en C#.
using System;
using System.IO;
namespace Articulos.Cap04
{
public sealed class UsoFuncTResult
{
public static void Main()
{
string texto = "MSDN: Microsoft Developer Network";
// Uso del delegado genérico Func<TResult>:
Func<bool> escritura = () => EscribirArchivo(texto);
// Valida que la escritura ha sido satisfactoria:
if (escritura())
{
Console.WriteLine ("La escritura del texto sobre el archivo ha sido satisfactoria.");
}
else
{
Console.WriteLine ("La operación de escritura ha fallado.");
}
}
public static bool EscribirArchivo(string texto)
{
try
{
StreamWriter sw = new StreamWriter("usofunctresult.txt", true);
sw.WriteLine (texto);
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