We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

rtipton on 05/15/09


Tagged

null Coalescing


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

paelgr
umang_nine


Null Coalescing Operator (??)


Published in: C# 


  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
Posted By: cmichaelgraham on May 19, 2009

nice !!

You need to login to post a comment.