What is the use of Null Coalescing Operator ( ?? ) in C#?
What is the use of Null Coalescing Operator ( ?? ) in C#?
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:
int? number = null;
int result = number ?? 0; // result = 0
string name = null;
string d...
middle
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào