elberon5.com

Coalesce in C#?

Posted by elberon5 Fri, 27 Apr 2007 20:12:00 GMT

I haven't played with this too much, but this is a neat thing I didn't know C# did.
  string foo = foo1 ?? foo2 ?? "N/A";

Comments

  1. gentooflux said 2 days later:
    I've been looking around for overloading for this one, I'm not sure it's possible since it's technically a logical operator and those can't be overloaded. Reason for that though is that while a null test works for most classes, I know I'm usually looking for either null or string.Empty when it comes to strings, so it'd be nice to overload coalesce to watch for that as well.
  2. Jake said 46 days later:
    String.IsNullOrEmpty() sounds like what you need, gentooflux

(leave url/email »)