
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What are lambda expressions in C#?
A lambda expression in C# describes a pattern. It has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.
The following is an example showing how to use lambda expressions in C# −
Example
using System; using System.Collections.Generic; class Demo { static void Main() { List<int> list = new List<int>() { 21, 17, 40, 11, 9 }; int res = list.FindIndex(x => x % 2 == 0); Console.WriteLine("Index: "+res); } }
Output
Index: 2
Above, we saw the usage of “goes to” operator to find the index of the even number −
list.FindIndex(x => x % 2 == 0);
The above example gives the following output.
Index: 2
Even number is at index 2 i.e. it is the 3rd element.
- Related Articles
- What are lambda expressions in Java?
- What are block lambda expressions in Java?
- Lambda Expressions in C#
- What are the characteristics of lambda expressions in Java?
- Are lambda expressions objects in Java?
- Generalized Lambda Expressions in C++14
- What are the advantages of Lambda Expressions in Java?\n
- What are lambda expressions and how to use them in Java?
- What are the scoping rules for lambda expressions in Java?\n
- What are the rules to follow while using exceptions in java lambda expressions?
- What is the syntax for lambda expressions in Java?
- What are regular expressions in C#
- Why we use lambda expressions in Java?
- How to debug lambda expressions in Java?
- What are anchors in regular expressions in C#?

Advertisements