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;
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.