Last active
August 29, 2015 14:02
-
-
Save Fhernd/4e5ad5511c1957244693 to your computer and use it in GitHub Desktop.
Demostración del delegado genérico Func<TResult>(out TResult) 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 class ConFunc | |
{ | |
public static void Main() | |
{ | |
SalidaContenido sc = new SalidaContenido(); | |
// Uso de Func<TResult>(out TResult): | |
Func<bool> delFunc = sc.EnviarAArchivo; | |
if (delFunc()) | |
{ | |
Console.WriteLine("La escritura fue satisfactoria."); | |
} | |
else | |
{ | |
Console.WriteLine("La escritura ha fallado."); | |
} | |
} | |
} | |
public class SalidaContenido | |
{ | |
public bool EnviarAArchivo() | |
{ | |
try | |
{ | |
StreamWriter sw = new StreamWriter("output1.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