Example using if-else statement:-
if (tempString == null)
{
x = "Null string";
}
else
{
x = tempString ;
}
Console.WriteLine(x);
Example using ?? Keyword
string tempString = null;
string x = tempString ?? "Null string";
Console.WriteLine(x); //Prints "Null string"
0 comments:
Post a Comment