Home > DeveloperSection > Forums > Lambda Expressions in C#
Ankit Singh

Total Post:341

Posted on    November-27-2015 10:27 PM

 C# C#  .NET 

 1 Reply(s)
 552  View(s)
Rate this:
I want to use Lambda Expressions in c# how to use please help me. 

aditya kumar Patel

Total Post:254

Posted on    November-27-2015 10:28 PM

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);



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

Don't want to miss updates? Please click the below button!

Follow MindStick