LAMBDA EXPRESSIONS IN C#

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#  .NET 
C#
 606  View(s)
Ratings:
Rate this:
I want to use Lambda Expressions in c# how to use please help me. 
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: Lambda Expressions in C#

    Lambda expressions are anonymous functions that contain expressions or sequence of operators. All lambda expressions use the lambda operator =>, that can be read as “goes to” or “becomes”.
    The left side of the lambda operator specifies the input parameters and the right side holds an expression or a code block that works with the entry parameters. Usually lambda expressions are used as predicates or instead of delegates (a type that references a method).
    Expression Lambdas
    Parameter => expression
    Parameter-list => expression
    Count => count + 2;
    Sum => sum + 2;
    n => n % 2 == 0
    The lambda operator => divides a lambda expression into two parts. The left side is the input parameter and the right side is the lambda body.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    public static class Lambda
    {
        public static void Main()
        {
            List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 };
            List<int> evenNumbers = list.FindAll(x => (x % 2) == 0);
            Console.Write("Even numbers :");
            foreach (var num in evenNumbers)
            {
              
                Console.Write("{0} ", num);
            }
            Console.WriteLine();
            Console.Read();

        }
    }

    c

      Modified On Nov-27-2015 10:30:39 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!