first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

“The C# ?? null coalescing operator”; Scott Guthrie

One of the subtle (but cool) language features of C# is the ?? “null coalescing” operator. This provides a nice, terse way to check whether a value is null, and if so return an alternate value.

The ?? operator works for both reference types and value types. For example, below we are checking whether the nullable integer “number” variable is null. Because it isn't, the result will be the original value (55):

int? number = 55;
int result = number ?? 0;

[http://weblogs.asp.net/scottgu/archive/2007/09/20/ the-new-c-null-coalescing-operator-and-using-it-with-linq.aspx]

mod date: 2009-08-11T03:51:47.000Z