2008-01-22

Code Simplification -- Lambdas FTW

Rick Brewster posted a beautifully simple try/catch wrapper for C# 3.0. I've wanted something like this for a few months now, but lacked the insight to figure it out on my own.

Read the linked article above for the full. Here's a sample usage of it.

string[] files = Patterns.TryCatch(() => Directory.GetFiles(@"C:\"), ex => new string[0]);
files.ForEach(Console.WriteLine);


Please note that files.ForEach is an Extension Method I wrote for simpler loops.

0 comments: