using System;
class NullHandling
{
public static void Main()
// Using the null-coalescing operator
int? x = null;
int y = x ?? 0; // y = 0 (if x is null)
Console.WriteLine(y);
// Using the null-conditional operator
// string name = "John";
string name = null;
string upperName = name?.ToUpper(); // upperName = "JOHN"
Console.WriteLine(upperName);
// Using the "is" operator
object value = null;
if (value is int i)
Console.WriteLine(i);
}
else
Console.WriteLine("value is not an int");
// Using the "as" operator
object obj = "Hello";
string str = obj as string; // str = "Hello"