Null Coalescing Operator (??)


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. using System;
  2. namespace CoalesceTst
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. string userName = "GabrielGray";
  9. string userName2 = null;
  10.  
  11. string name = userName ?? "<no name>";
  12. string name2 = userName2 ?? "<no name>";
  13.  
  14. Console.WriteLine(name);
  15. Console.WriteLine(name2);
  16. }
  17. }
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.