top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is lambda expression in C#?

+2 votes
256 views
What is lambda expression in C#?
posted Nov 26, 2014 by Manikandan J

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

A lambda expression:

It is an anonymous Functionalist that you can use to create delegates or expression tree types.To create a lambda expression, you specify input parameters on the left side of the lambda operator =>, and you put the expression or statement block on the other side. For example, the lambda expression x => x * x .

Example as below

using System.Linq.Expressions;
namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        Expression del myET = x => x * x;
    }
}

Program that uses lambda expressions: C

using System;
class Program
{
static void Main()
  { 

 Function Function1 = x => x + 1; 

 Function Function2 = x => { return x + 1; }; 

 Functiontion Function3 = (int x) => x + 1; 

 Function Function4 = (int x) => { return x + 1; }; 

 Function Function5 = (x, y) => x * y; 

 Action Function6 = () => Console.WriteLine(); 

Function Function7 = delegate(int x) { return x + 1; }; 

 Function Function8 = delegate { return 1 + 1; }; 

 Console.WriteLine(Function1.Invoke(1)); 

 Console.WriteLine(Function2.Invoke(1)); 

 Console.WriteLine(Function3.Invoke(1)); 

 Console.WriteLine(Function4.Invoke(1)); 

 Console.WriteLine(Function5.Invoke(2, 2)); 

 Function6.Invoke(); 

 Console.WriteLine(Function7.Invoke(1)); 

 Console.WriteLine(Function8.Invoke());

         }

    }

}
answer Nov 26, 2014 by Jdk
Similar Questions
+3 votes

By-default all the methods & variables in class are private.

In C#.net Main() method is private then how compiler access this Main() Method out side the class because compiler is not part of our program then how compiler access this Main() method?

Here we loose our data abstraction property ? Can anyone put some light on it?

...