Thursday, May 24, 2012

C# LIST.FOREACH +lambda example

never found a really simple example, see this:
List<string> parts = new List<string>();
parts.ForEach(delegate (string p) {
     Console.WriteLine(p);    });
since in lambda () is delegate() so
List<DateTime> dates = new List<DateTime>(); // just to show that T doesnt matter
parts.ForEach((DateTime d) =>
{
      Console.WriteLine(d);
});
PLUS u can do the remarkable list.Remove(d)! unlike foreach

No comments:

Post a Comment