C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Definitions » General »

What is a Lambda expression?


Posted Date: 17 Oct 2009    Resource Type: Definitions    Category: General
Author: Gaurav AroraMember Level: Diamond    
Rating: 4 out of 54 out of 54 out of 54 out of 5Points: 7



A Lambda expression is nothing but an Anonymous Function, can contain expressions and statements. Lambda expressions can be used mostly to create delegates or expression tree types. Lambda expression uses lambda operator => and read as ‘goes to’ operator.

Left side of this operator specifies the input parameters and contains the expression or statement block at the right side.

Example: myExp = myExp/10;

Now, let see how we can assign the above to a delegate and create an expression tree:


delegate int myDel(int intMyNum);

static void Main(string[] args)

{

//assign lambda expression to a delegate:

myDel myDelegate = myExp => myExp / 10;

int intRes = myDelegate(110);

Console.WriteLine(”Output {0}”, intRes);

Console.ReadLine();

//Create an expression tree type

//This needs System.Linq.Expressions

Expression myExpDel = myExp => myExp /10;

}


Note:

The => operator has the same precedence as assignment (=) and is right-associative.

Lambdas are used in method-based LINQ queries as arguments to standard query operator methods such as Where.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
LINQ  .  Lambda Expression  .  Anonymous function  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: CSS - Cascading Style Sheets
Previous Resource: Laptop
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use