Skip to content

Instantly share code, notes, and snippets.

@thedom85
Created March 27, 2015 14:44
Show Gist options
  • Save thedom85/f4dd2f4e751616845517 to your computer and use it in GitHub Desktop.
Save thedom85/f4dd2f4e751616845517 to your computer and use it in GitHub Desktop.
CSharp_Lambda_ForEach_Expression_Func.cs
void Main()
{
var mySourceStringArray = new string[] { "1", "2", "3", "4"};
var myDestinationStringList = new List<string>();
mySourceStringArray.ForEach(myDestinationStringList.Add);
myDestinationStringList.ForEach(x => Debug.Write(x + " "));
}
public static class EnumerableExtension
{
public static void ForEach<T>(this IEnumerable<T> self, Action<T> action)
{
if (action == null) return;
foreach (var item in self)
action.Invoke(item);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment