.NET

C# Advanced Features

Pattern matching, records, tuples, deconstruction, local functions, ref/out parameters

20 câu hỏi phỏng vấn·
Mid-Level
1

What is a record in C#?

Câu trả lời

A record is an immutable reference type introduced in C# 9 that provides concise syntax for creating data types with value-based equality. Unlike regular classes which use reference equality, records compare the values of their properties. Use records for DTOs, value objects, and immutable types where value-based equality is desirable.

2

What is the difference between out and ref in C#?

Câu trả lời

The out parameter does not require initialization before method call but must be assigned in the method, while ref requires initialization before call and may or may not be modified in the method. Both pass by reference but out is optimized for returning multiple values while ref is used to modify an existing variable. Use out for methods returning multiple results and ref when modification of an existing value is needed.

3

What is pattern matching in C#?

Câu trả lời

Pattern matching is a feature that allows testing a value against different patterns (types, values, properties) and executing code based on the matching pattern. Introduced in C# 7 and enhanced in later versions, it simplifies complex conditional structures with switch expressions, property patterns and type patterns. Use pattern matching to replace complex if-else chains and improve code readability.

4

What is a tuple in C# and how to declare it?

5

What is a local function in C#?

+17 câu hỏi phỏng vấn

Nắm vững .NET cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí