.NET

C# Advanced Features

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

20 preguntas de entrevista·
Mid-Level
1

What is a record in C#?

Respuesta

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#?

Respuesta

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#?

Respuesta

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 preguntas de entrevista

Domina .NET para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis