Lambda Expression


Here's a quick code reference for using a lambda expression.

Sample of the Original (old) Way

For code construct :

Array.FindIndex(string[] array, Predicate<string> match)

Assuming that array parameter is defined, and Predicate<string> is defined as follows:

delegate(string obj) { return obj == "Test"; } )

we can replace it by using lambda expression.

Sample of the Lambda Expression Usage

Instead of using delegate for the Predicate<T> parameter, we now can use the following:

obj => obj == "Test"
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License