SlideShare a Scribd company logo
C# Lambda Expression
 Lambda expressions use special syntax. They allow
functions to be used as data such as variables or
fields. The lambda expression syntax uses the =>
operator. This separates the parameters and
statement body of the anonymous function.
Example :~
 This program uses lambda expressions and other
anonymous functions. The source text uses the =>
operator. This is a syntax for separating the
parameters to a method from the statements in the
method's body.
 Tip: Lambda expressions use the token => in an
expression context. In this context, the token is not
a comparison operator.
Token :~
 The => operator can be read as "goes to" and it is
always used when declaring a lambda expression. A
lambda expression allows you to use a function with
executable statements as a parameter, variable or
field.
Methods :~
using System;
class Program
{
static void Main()
{
//
// Use implicitly typed lambda expression.
// ... Assign it to a Func instance.
//
Func<int, int> func1 = x => x + 1;
//
// Use lambda expression with statement body.
//
Func<int, int> func2 = x => {return x + 1; };
//
// Use formal parameters with expression body.
//
Func<int, int> func3 = (int x) => x + 1;
//
// Use parameters with a statement body.
//
Func<int, int> func4 = (int x) => { return x + 1; };
//
// Use multiple parameters.
//
Func<int, int, int> func5 = (x, y) => x * y;
//
// Use no parameters in a lambda expression.
//
Action func6 = () => Console.WriteLine();
//
// Use delegate method expression.
//
Func<int, int> func7 = delegate(int x) { return x + 1;
};
//
// Use delegate expression with no parameter list.
//
Func<int> func8 = delegate { return 1 + 1; };
// Invoke each of the lambda expressions and delegates
we created.
// ... The methods above are executed.
Console.WriteLine(func1.Invoke(1));
Console.WriteLine(func2.Invoke(1));
Console.WriteLine(func3.Invoke(1));
Console.WriteLine(func4.Invoke(1));
Console.WriteLine(func5.Invoke(2, 2));
func6.Invoke();
Console.WriteLine(func7.Invoke(1));
Console.WriteLine(func8.Invoke());
}
}
Output
2
2
2
2
4
2
2
In the example, we see the => syntax. This can be read as "goes
to." It separates the arguments from the method body of a lambda
expression. It is not a comparison operator. The => syntax
separates the left from the right.
Left side: This is an empty parameter list, a formal parameter list,
or an implicit parameter list from the body.
Right side: This can be a statement list inside curly brackets with
a return statement, or an expression.
C# LINQ
 LINQ. Imperative code describes how to complete an
algorithm.
It proceeds step by step, emphasizing process, not
result. Declarative code (like LINQ) describes the
end result
 This technology, Language Integrated Query,
introduces extension methods. These work on Lists
and arrays. We even use them on collections not yet
in memory.
 Example:We use the Average extension method to
average all the elements in an int array. A double
value is returned.
 Tip:The Average method is implemented as an
extension method within the .NET Framework.
Extension methods have special syntax.
Program that uses LINQ extension: C#
using System;
using System.Linq;
class Program
{
static void Main()
{
int[] array = { 1, 3, 5, 7 };
Console.WriteLine(array.Average());
}
}
Output
4

More Related Content

What's hot (20)

PPTX
Storage Class Specifiers in C++
Reddhi Basu
 
PPT
Functions in c
SunithaVesalpu
 
PPTX
C language presentation
bainspreet
 
PPT
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
PPTX
Java 8 Lambda Expressions
Hyderabad Scalability Meetup
 
PPT
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
PPTX
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
PPTX
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
PPTX
Decision statements in c language
tanmaymodi4
 
PDF
Cpp functions
NabeelaNousheen
 
PDF
Learn Java Part 2
Gurpreet singh
 
PPTX
Storage class in C Language
Nitesh Kumar Pandey
 
PPTX
Storage class
Joy Forerver
 
PPTX
Function C++
Shahzad Afridi
 
PPTX
11 lec 11 storage class
kapil078
 
PDF
Java 8
Sheeban Singaram
 
PPTX
Storage class in c
kash95
 
PPT
Storage classes
Shanmughaneethi Velu
 
PDF
PLSQL CURSOR
Arun Sial
 
Storage Class Specifiers in C++
Reddhi Basu
 
Functions in c
SunithaVesalpu
 
C language presentation
bainspreet
 
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
Java 8 Lambda Expressions
Hyderabad Scalability Meetup
 
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Decision statements in c language
tanmaymodi4
 
Cpp functions
NabeelaNousheen
 
Learn Java Part 2
Gurpreet singh
 
Storage class in C Language
Nitesh Kumar Pandey
 
Storage class
Joy Forerver
 
Function C++
Shahzad Afridi
 
11 lec 11 storage class
kapil078
 
Storage class in c
kash95
 
Storage classes
Shanmughaneethi Velu
 
PLSQL CURSOR
Arun Sial
 

Viewers also liked (18)

DOCX
Lecture1 oopj
Dhairya Joshi
 
DOCX
Lecture6 oopj
Dhairya Joshi
 
PPTX
MTA animations graphics_accessing data
Dhairya Joshi
 
DOCX
Business and new economic enviornment
Dhairya Joshi
 
PPTX
Javascript regular expression
Dhairya Joshi
 
PPTX
Css box model
Dhairya Joshi
 
PPT
Software engg. pressman_ch-21
Dhairya Joshi
 
PPTX
MTA css layouts
Dhairya Joshi
 
PPT
Chapter 8 switching -computer_network
Dhairya Joshi
 
DOCX
Lecture3 oopj
Dhairya Joshi
 
PPT
Chapter 5 analog transmission computer_network
Dhairya Joshi
 
DOCX
Lecture9 oopj
Dhairya Joshi
 
PPTX
MTA managing the graphical interface by using css
Dhairya Joshi
 
PPT
Website design principles
Dhairya Joshi
 
DOCX
Lecture7 oopj
Dhairya Joshi
 
PPTX
MTA html5 text_graphics_media
Dhairya Joshi
 
PPT
Software engg. pressman_ch-8
Dhairya Joshi
 
PPTX
Ajax
Dhairya Joshi
 
Lecture1 oopj
Dhairya Joshi
 
Lecture6 oopj
Dhairya Joshi
 
MTA animations graphics_accessing data
Dhairya Joshi
 
Business and new economic enviornment
Dhairya Joshi
 
Javascript regular expression
Dhairya Joshi
 
Css box model
Dhairya Joshi
 
Software engg. pressman_ch-21
Dhairya Joshi
 
MTA css layouts
Dhairya Joshi
 
Chapter 8 switching -computer_network
Dhairya Joshi
 
Lecture3 oopj
Dhairya Joshi
 
Chapter 5 analog transmission computer_network
Dhairya Joshi
 
Lecture9 oopj
Dhairya Joshi
 
MTA managing the graphical interface by using css
Dhairya Joshi
 
Website design principles
Dhairya Joshi
 
Lecture7 oopj
Dhairya Joshi
 
MTA html5 text_graphics_media
Dhairya Joshi
 
Software engg. pressman_ch-8
Dhairya Joshi
 
Ad

Similar to Linq & lambda overview C#.net (20)

DOCX
Mastering C# Lambda Expressions: A Complete Guide
LetsUpdateSkills
 
PPTX
Lamdha.pptx
ControlUrgentSecurit
 
PPTX
Fun with lambda expressions
Mike Melusky
 
PPTX
Lambdas and Extension using VS2010
vgrondin
 
PPTX
Fun with lambda expressions
Mike Melusky
 
PPTX
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Jaliya Udagedara
 
PDF
New c sharp3_features_(linq)_part_ii
Nico Ludwig
 
ODP
Can't Dance The Lambda
Togakangaroo
 
PPTX
C#-LINQ-and-Lambda-Expression
Simplilearn
 
PPTX
Linq and lambda
John Walsh
 
PPTX
Evolution of C# delegates
mbaric
 
PDF
Lambda Expression For anyone that needs Java Lambda notes
shreyansh15388
 
PPT
Of Lambdas and LINQ
BlackRabbitCoder
 
PPTX
Introduction of lambda expression and predicate builder
LearningTech
 
PPTX
Lambda expressions
Yuriy Seniuk
 
PPT
Csharp4 delegates lambda_and_events
Abed Bukhari
 
PPTX
Java 8 features
Maýur Chourasiya
 
PDF
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
PPT
20130329 introduction to linq
LearningTech
 
PPTX
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
Mastering C# Lambda Expressions: A Complete Guide
LetsUpdateSkills
 
Fun with lambda expressions
Mike Melusky
 
Lambdas and Extension using VS2010
vgrondin
 
Fun with lambda expressions
Mike Melusky
 
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
Jaliya Udagedara
 
New c sharp3_features_(linq)_part_ii
Nico Ludwig
 
Can't Dance The Lambda
Togakangaroo
 
C#-LINQ-and-Lambda-Expression
Simplilearn
 
Linq and lambda
John Walsh
 
Evolution of C# delegates
mbaric
 
Lambda Expression For anyone that needs Java Lambda notes
shreyansh15388
 
Of Lambdas and LINQ
BlackRabbitCoder
 
Introduction of lambda expression and predicate builder
LearningTech
 
Lambda expressions
Yuriy Seniuk
 
Csharp4 delegates lambda_and_events
Abed Bukhari
 
Java 8 features
Maýur Chourasiya
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
20130329 introduction to linq
LearningTech
 
Lambda Expressions Java 8 Features usage
AsmaShaikh478737
 
Ad

Recently uploaded (20)

PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 

Linq & lambda overview C#.net

  • 1. C# Lambda Expression  Lambda expressions use special syntax. They allow functions to be used as data such as variables or fields. The lambda expression syntax uses the => operator. This separates the parameters and statement body of the anonymous function. Example :~  This program uses lambda expressions and other anonymous functions. The source text uses the => operator. This is a syntax for separating the parameters to a method from the statements in the method's body.  Tip: Lambda expressions use the token => in an expression context. In this context, the token is not a comparison operator. Token :~  The => operator can be read as "goes to" and it is always used when declaring a lambda expression. A lambda expression allows you to use a function with executable statements as a parameter, variable or field. Methods :~ using System; class Program { static void Main() { // // Use implicitly typed lambda expression. // ... Assign it to a Func instance.
  • 2. // Func<int, int> func1 = x => x + 1; // // Use lambda expression with statement body. // Func<int, int> func2 = x => {return x + 1; }; // // Use formal parameters with expression body. // Func<int, int> func3 = (int x) => x + 1; // // Use parameters with a statement body. // Func<int, int> func4 = (int x) => { return x + 1; }; // // Use multiple parameters. // Func<int, int, int> func5 = (x, y) => x * y; // // Use no parameters in a lambda expression. // Action func6 = () => Console.WriteLine(); // // Use delegate method expression. // Func<int, int> func7 = delegate(int x) { return x + 1; }; // // Use delegate expression with no parameter list. // Func<int> func8 = delegate { return 1 + 1; };
  • 3. // Invoke each of the lambda expressions and delegates we created. // ... The methods above are executed. Console.WriteLine(func1.Invoke(1)); Console.WriteLine(func2.Invoke(1)); Console.WriteLine(func3.Invoke(1)); Console.WriteLine(func4.Invoke(1)); Console.WriteLine(func5.Invoke(2, 2)); func6.Invoke(); Console.WriteLine(func7.Invoke(1)); Console.WriteLine(func8.Invoke()); } } Output 2 2 2 2 4 2 2 In the example, we see the => syntax. This can be read as "goes to." It separates the arguments from the method body of a lambda expression. It is not a comparison operator. The => syntax separates the left from the right. Left side: This is an empty parameter list, a formal parameter list, or an implicit parameter list from the body. Right side: This can be a statement list inside curly brackets with a return statement, or an expression.
  • 4. C# LINQ  LINQ. Imperative code describes how to complete an algorithm. It proceeds step by step, emphasizing process, not result. Declarative code (like LINQ) describes the end result  This technology, Language Integrated Query, introduces extension methods. These work on Lists and arrays. We even use them on collections not yet in memory.  Example:We use the Average extension method to average all the elements in an int array. A double value is returned.  Tip:The Average method is implemented as an extension method within the .NET Framework. Extension methods have special syntax. Program that uses LINQ extension: C# using System; using System.Linq; class Program { static void Main() { int[] array = { 1, 3, 5, 7 }; Console.WriteLine(array.Average()); } } Output 4