

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use Null Coalescing Operator (??) in C#?
The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.
If the value of the first operand is null, then the operator returns the value of the second operand, otherwise, it returns the value of the first operand.
The following is an example −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { double? num1 = null; double? num2 = 6.32123; double num3; num3 = num1 ?? 9.77; Console.WriteLine(" Value of num3: {0}", num3); num3 = num2 ?? 9.77; Console.WriteLine(" Value of num3: {0}", num3); Console.ReadLine(); } } }
Output
Value of num3: 9.77 Value of num3: 6.32123
- Related Questions & Answers
- Difference between the Ternary operator and Null coalescing operator in php
- What is a "null coalescing" operator in JavaScript?
- Is there a “null coalescing” operator in JavaScript?
- How to use Operator Overloading in C#?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- How to use NULL in MySQL SELECT statement?
- How to use an assignment operator in C#?
- How to use the ?: conditional operator in C#?
- How to use the instanceof operator in Java?
- How to use *= operator in jQuery attribute selector?
- How to use INTERSECT operator in Android sqlite?
- How to use IS NOT NULL in Android sqlite?
- How to use NOT NULL constraints in Android sqlite?
- How to use ‘as’ operator in C#?
- How to use ‘is’ operator in C#?
Advertisements