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:

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:
int? number = null;
int result = number ?? 0; // result = 0
  1. Providing a default value for reference types:
string name = null;
string d...
middle

middle

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

senior

What is the Constructor Chaining in C#?

middle

Explain assignment vs shallow copy vs deep copy for a Record in C#

junior

What is an Abstract Class?

Bình luận

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

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