.NET Course
  • Welcome developers
  • LINQ
    • Advanced c# overview
      • Implicit typing
      • Generics
      • Attributes
      • Reflection
      • Delegates
      • Anonymous Methods and Lambda Expressions
      • Events
      • Anonymous Types
      • Ref vs Out
      • Task
      • TaskFactory
      • Asynchronous programming with async and await
      • Abstract class VS Interface
      • Inheritance, Composition and Aggregation in C#
    • LINQ Tutorial
      • Loading Related Entities
      • Lambda Expression
      • Standard Query Operators
    • Testing ASP.NET Core
      • Implementing unit tests for ASP.NET Core Web APIs
    • Software development principles
      • Object-Oriented Programming (Principles)
      • N-tier architecture style
      • Command and Query Responsibility Segregation (CQRS) pattern
      • SOLID: The First 5 Principles of Object Oriented Design
  • Helping links
    • SonarQube installation and tutorial for .net core projects
  • C# .NET Interview Questions
    • Ultimate C# Interview questions
      • Part 4
      • Part 3
      • Part 2
      • Part 1
  • Unit test .NET Core xUnit & MOQ
    • Content
      • Snippets
      • Traits
Powered by GitBook
On this page

Was this helpful?

  1. LINQ
  2. LINQ Tutorial

Lambda Expression

Anatomy of the Lambda Expression

C# 3.0(.NET 3.5) introduced the lambda expression along with LINQ. The lambda expression is a shorter way of representing anonymous method using some special syntax.

For example, following anonymous method checks if student is teenager or not:

delegate(Student s) { return s.Age > 12 && s.Age < 20; };

The above anonymous method can be represented using a Lambda Expression in C# and VB.Net as below:

s => s.Age > 12 && s.Age < 20

Lambda Expression in VB.Net

Function(s) s.Age  > 12 And s.Age < 20

Let's see how the lambda expression evolved from the following anonymous method.

delegate(Student s) { return s.Age > 12 && s.Age < 20; };

The Lambda expression evolves from the anonymous method by first removing the delegate keyword and parameter type and adding a lambda operator =>.

PreviousLoading Related EntitiesNextStandard Query Operators

Last updated 3 years ago

Was this helpful?