Hi,/P>
Continuing with my work on different Lambda expression. Here are some more Lambda’s that I wrote (when I was practicing them).You can get my previous example herehttp:////www.vikramlakhotia.com//Starting_with_the_basic_of_Lambda_Expression.aspx/A>http:////www.vikramlakhotia.com//Some_examples_on_how_to_use_Lambda_Expression.aspx/A>http:////www.vikramlakhotia.com//Using_Lambda_expressions_in_LINQ.aspx/A>To get the first record matching certain condition in the liststring strVal = SomesTringCollection.First(str => str[0] == 'V');As you would have guessed to get the last record we have a Last method/P> string strVal = SomesTringCollection.Last(str => str[0] == 'V');Another of very important usage of /SPAN>Lambda can be to create a new anoynomoust type. We can use the select method to create a new anoynomoys types in a Lambda expression. Here is an example.var NewAnonymousType = strVal.Select(s => new {FirstName = s.Substring(0,10), LastName = s.Substring(10)});/P> Lambda expression can be used in the grouping also. Below is an example where by I am using a Lambda expression to group Number in Odd and Even; /SPAN>int[] iList = new []{1,2,3,4,5,6,7,8,9};/P>iList.GroupBy(i => i%2 == 0);Vikram/SPAN>
string strVal = SomesTringCollection.Last(str => str[0] == 'V');Another of very important usage of /SPAN>Lambda can be to create a new anoynomoust type. We can use the select method to create a new anoynomoys types in a Lambda expression. Here is an example.var NewAnonymousType = strVal.Select(s => new {FirstName = s.Substring(0,10), LastName = s.Substring(10)});/P> Lambda expression can be used in the grouping also. Below is an example where by I am using a Lambda expression to group Number in Odd and Even; /SPAN>int[] iList = new []{1,2,3,4,5,6,7,8,9};/P>iList.GroupBy(i => i%2 == 0);Vikram/SPAN>
Lambda expression can be used in the grouping also. Below is an example where by I am using a Lambda expression to group Number in Odd and Even; /SPAN>int[] iList = new []{1,2,3,4,5,6,7,8,9};/P>iList.GroupBy(i => i%2 == 0);Vikram/SPAN>
Thsna for givig the good expamle of lambda expression. /p>
regrdas satya www.walkincg.com /p>
Thanks a lot! These are really very good examples. /p>
thanks! /p>
string strVal = SomesTringCollection.First(str => str[0] == 'V'); - I'm confused here :( /p>