.NET

LINQ & Delegates

LINQ query syntax, method syntax, delegates, events, lambda expressions, func/action

20 perguntas de entrevistaยท
Junior
1

What is a delegate in C#?

Resposta

A delegate is a type that represents references to methods with a particular signature. It allows passing methods as parameters, storing them in variables, and invoking them dynamically. Delegates are the foundation of events and callbacks in C#, providing essential flexibility for event-driven programming and design patterns like Strategy or Observer.

2

What is the correct syntax for declaring a simple lambda expression?

Resposta

The syntax (x) => x * 2 is the correct form for a lambda expression. The => symbol (called the "lambda operator") separates parameters from the expression or method body. This concise syntax allows creating inline anonymous functions, very useful with LINQ or for passing behaviors as parameters. Parentheses around the parameter can be omitted if there is only one.

3

Which generic delegate should be used for a method that takes an int and returns a string?

Resposta

Func<int, string> is the appropriate generic delegate because Func is used for methods that return a value. The convention is that the last type parameter represents the return type, and the preceding ones represent input parameters. Func can accept up to 16 input parameters. For methods with no return value, Action should be used instead of Func.

4

What is the main difference between Func and Action?

5

What does LINQ stand for?

+17 perguntas de entrevista

Domine .NET para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis