Created
June 10, 2014 16:58
-
-
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#.
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 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