■
Note
C# 2008 also allows you to represent lambda expressions as an in-memory object using expression
trees. This can be very useful for third parties who are building software that needs to extend the functionality of
existing lambdas, as well as when programming with Language Integrated Query (LINQ). Consult the .NET Frame-
work 3.5 SDK documentation.
To set the stage for our examination of lambda expressions, create a new Console Application
named SimpleLambdaExpressions. Now, consider the FindAll() method of the generic List
type. This method is expecting a generic delegate of type System.Predicate, used to wrap any
method returning a Boolean and taking a specified T as the only input parameter. Add a method
(named TraditionalDelegateSyntax()) within your Program type that interacts with the System.
Predicate type to discover the even numbers in a List of integers:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Lambdas *****\n");
TraditionalDelegateSyntax();
Console.ReadLine();
}
static void TraditionalDelegateSyntax()
{
Do'stlaringiz bilan baham: |