.NET

LINQ & Delegates

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

20 면접 질문·
Junior
1

What is a delegate in C#?

답변

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?

답변

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?

답변

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 면접 질문

다음 면접을 위해 .NET을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기