This C# program demonstrates how use the null coalescing operator.
using System;
namespace XoaX {
class Program {
static void Main(string[] args) {
string[] saPersons = new string[] { "Father", "Son", "Holy Spirit", "" };
string[] saCheck = new string[] { null, null, null, null };
for (int i = 0; i < 4; ++i) {
// The null coalescing chain selects the first that is not null
Console.WriteLine(saCheck[2] ?? saCheck[1] ?? saCheck[0] ?? "All null");
saCheck[i] = saPersons[i];
}
}
}
}
All null Father Son Holy Spirit Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.