After learning about the Action delegate in C# I've been looking for ways I can best use it in my code. I came up with this pattern:
Action<string> DoSomething = (lSomething) =>
{
// Do something
};
DoSomething("somebody");
DoSomething("someone");
DoSomething("somewhere");
If I were to have used a traditional loop, it would look something like this:
List<string> lSomeList = new List<string>();
lSomeList.Add("somebody");
lSomeList.Add("someone");
lSomeList.Add("somewhere");
foreach (string lSomething in lSomeList)
{
// Do something
}
Are there any appreciable differences between the two? To me they look equally easy to understand and maintain, but are there some other criteria I might use to distinguish when one might be preferred over the other?