Friday 21 January 2011

Lambda expression VS deletgate

Just a quick one to show how you can use lambda expressions to replace lengthy delegate syntax.

The following two statements are equivalent:

List<int> intFreshAgencies = strFreshAgencies.ConvertAll<int>(s => int.Parse(s));
List<int> intFreshAgencies2 = strFreshAgencies.ConvertAll<int>(delegate(string s) { return int.Parse(s); });

1 comment:

  1. Here is a good article which describes the basics of Lambda expressions and Delegates in .Net:

    http://www.devx.com/codemag/Article/39674/0/page/1

    ReplyDelete