Created
March 27, 2015 14:44
-
-
Save thedom85/f4dd2f4e751616845517 to your computer and use it in GitHub Desktop.
CSharp_Lambda_ForEach_Expression_Func.cs
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
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