public static void Main()
Console.WriteLine(TryDoSomething(() => { return "Hello World"; }));
Console.WriteLine(TryDoSomething(() => { return 512; }));
Console.WriteLine(TryDoSomething(() => { return new byte[] {1, 2, 3}; }));
Console.WriteLine(TryDoSomething(ReturnAString));
Console.WriteLine(TryDoSomething(() => { return "This will fail"; }, true));
Console.WriteLine(TryDoSomething(() => { return 5; }, true));
private static T TryDoSomething<T>(Func<T> method, bool fail = false)
private static string ReturnAString()
return "This is a string";