Sobes.tech
Junior — Middle

Could you explain the concept of Lambda expressions in programming?

sobes.tech AI

Answer from AI

Lambda expressions in programming are anonymous functions that can be passed as parameters, stored in variables, and used for concise behavior descriptions.

In C#, lambda expressions allow writing short functions without the need to create a separate method. They are often used with LINQ and delegates.

Example:

Func<int, int> square = x => x * x;
int result = square(5); // result will be 25

Here, x => x * x is a lambda expression that takes a parameter x and returns its square. This simplifies the code and improves readability.