Lambda Expressions Flashcards Preview

.NET / C# > Lambda Expressions > Flashcards

Flashcards in Lambda Expressions Deck (13)
Loading flashcards...
1

What is a lambda expression?

A lambda expression is an anonymous function that you can use to create delegates or expression tree types.

2

Before lambda expressions, how methods were called?

They were called as named methods (regular methods). Or they would be called as delegate methods (noisy syntax).

3

Hows does this (deprecated?) anonymous delegated method called?

linq cities.where(delegate(string s) {return s.StartsWith("L"); });

4

Hows does a lambda expression look like?

linq cities.where(s => s.StartsWith("L"));

5

Is it really necessary to have lambda expression with one letter params (e.g e.Name)?

No... you can have full names, such as employee => e.Name. But as the whole intention of lambda expressions is to save up time and space this became very common.

6

How does visual studio show in auto-complete, that the method you're calling receives a lambda expression?

(Func predicate)

7

How many parameters a lambda expression can have?

Up to 17.

8

How does a func type look like?

Func

9

Hows the compiler now which param is the return?

Is always the last one

10

How to declare a func and create a lambda expression that implements it?

Func square = x => x * x;

11

When is it necessary to have a parenthesis in the lambda expression?

When the Func expression takes 0 or more than one parameters. e.g: Func add = (x, y) => x+ y;

12

What happens when the lambda expressions is kinda big and needs more than one line of code to implement it? What is necessary to be done then?

You need to add a pair of curly braces and then it is necessary to define a return keyword. e.g: func add => (x, y) => {
int temp = x+y;
return temp;
};

13

How to declare a lambda expression that returns void?

It is called Action and is declared as: Action write = x => Console.WriteLine(x);