C# 2.0 NULL Coalescing Operator

Software

OK, I’m a little behind the times, but I just found out there was a neat way to sidestep 90% of the null checks I do in my ternary operators:

output = (value == null) ? "NULL" : value;

becomes

output = (value ?? "NULL");

(h/t R. Aaron Zupancic)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Furl
  • Ma.gnolia
  • Reddit
  • TwitThis
No Comments

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">