Lambda Expressions in C#

Posted by in LINQ category on for Beginner level | Views : 11078 red flag

This Article demonstrate the basic functionality of Lambda Expression in C#(Console Application).
About Lambda Expression
  • A lambda expression is an function that contain many expressions and statements.
  • Lambda expression used to create delegates or expression tree types.
  • All lambda expressions use the lambda operator =>, which is read as "goes to".
  • The left side of the lambda operator specifies the input parameters.
  • The right side holds the expression or statement block

 Lambda Expression used to Create two ways.

  1.     Delegates
  2.     Expression Tree Types.
  Delegates with Examples

  Single Parameter

       The lambda expression Y => Y * Y is read "Y goes to Y times Y."

 delegate int ADD(int i);
 static void Main(string[] args)
    ADD Delgts = i => i * i;
    int K = Delgts(5);

Output : 25
  Multiple Parameter
   delegate int ADD(int i,int y );
       static void Main(string[] args)
            ADD Delgts = (i, Z) => i * Z;
            int K = Delgts(10, 20);

                   Output :200

Lambdas with Standard Query Operators standard query operator, the Count method

int[] Numb = { 15, 14, 11, 13, 19,18,16, 17, 12, 10 };

            int TotalOddno = Numb.Count(n => n % 2 == 1);


                         Output : 5
This article shows basic about LAMBDA Expressions.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Muhil an
Member Level:
Member Status: Member
Member Since: 11/30/2009 2:46:25 AM
Country: India

working as an IT System Analyst,tmuhilan at gmail com

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)