0
0
C Sharp (C#)programming~15 mins

Expression-bodied lambdas in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Expression-bodied Lambdas in C#
📖 Scenario: You are working on a small program that processes a list of numbers. You want to use simple functions to perform calculations on these numbers.
🎯 Goal: Learn how to write expression-bodied lambda functions in C# to make your code shorter and easier to read.
📋 What You'll Learn
Create a list of integers
Create an expression-bodied lambda to double a number
Use the lambda to create a new list with doubled values
Print the new list
💡 Why This Matters
🌍 Real World
Expression-bodied lambdas are used to write short, clear functions for data processing, event handling, and callbacks in many C# applications.
💼 Career
Knowing how to write concise lambdas helps you write cleaner code and work efficiently in C# development jobs.
Progress0 / 4 steps
1
Create a list of integers
Create a list of integers called numbers with these exact values: 1, 2, 3, 4, 5
C Sharp (C#)
Need a hint?

Use List<int> and initialize it with the values inside curly braces.

2
Create an expression-bodied lambda to double a number
Create an expression-bodied lambda called doubleNumber that takes an int parameter n and returns n * 2
C Sharp (C#)
Need a hint?

Use Func<int, int> and the lambda arrow => with a single expression.

3
Use the lambda to create a new list with doubled values
Create a new list of integers called doubledNumbers by using numbers.ConvertAll with the doubleNumber lambda
C Sharp (C#)
Need a hint?

Use ConvertAll method on the numbers list and pass doubleNumber as the converter.

4
Print the new list
Use a foreach loop to print each number in doubledNumbers on its own line
C Sharp (C#)
Need a hint?

Use foreach (int num in doubledNumbers) and inside the loop use Console.WriteLine(num);.