The null-coalescing operator ?? returns the value of its left-hand operand if it isn’t null; otherwise, it evaluates the right-hand operand and returns its result. The ?? operator doesn’t evaluate its right-hand operand if the left-hand operand evaluates to non-null. int? myValue = null; int result = myValue ?? -1; //result = -1; Syntax: p ?? q Here, p is […]
Tag: Null-Coalescing
Null-Conditional (?) and Null-Coalescing (??) Operators in C#
Null coalescing: The null coalescing operator “??” uses two question marks. With it you can use a custom value for a null reference variable. It simplifies null tests. C# program that uses null coalescing operator using System; class Program { static string _name; /// <summary> /// Property with custom value when null. /// </summary> static […]