Câu hỏi phỏng vấn C#
Câu hỏi

What is the use of Null Coalescing Operator ( ?? ) in C#?

Câu trả lời

The null coalescing operator (??) in C# is used to provide a default value for a nullable type or reference type when the value is null. It allows you to write more concise and readable code when handling null values.

Here's how it works:

csharp Copy
value ?? defaultValue

If value is not null, the null coalescing operator returns value. Otherwise, it returns defaultValue.

Some common use cases for the null coalescing operator include:

  1. Providing a default value for nullable types:
csharp Copy
int? number = null;
int result = number ?? 0; // result = 0
  1. Providing a default value for reference types:
csharp Copy
string name = null;
string d...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Why can't you specify the accessibility modifier for methods inside the Interface?

senior

What is the best practice to have best performance using Lazy objects?

expert

Explain when to use Finalize vs Dispose ?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào