Answers for "c# null coalescing operator"

C#
8

null coalescing operator c#

//the null coalescing operator for c# is ??
int? x = null;
int y = 9;
return x ?? y; 
//Will return the value of x if x is not null else return y
Posted by: Guest on May-06-2020
1

c# null coalescing operator

static void Sample(string input)
{
    string result = input ?? "default";
    Console.WriteLine($"Result: {result}");
}
Posted by: Guest on July-17-2021
1

c# null conditional

//Return stirng representation of nullable DateTime
DateTime? x = null;
return x.HasValue == true ? x.Value.ToString() : "No Date";
Posted by: Guest on June-10-2020
0

c# null accessor

int? length = people?.Length; // null if people is null
Posted by: Guest on July-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language