You learn somthing new everyday - that’s what I love about this job… any way the C# null-coalescing operator

You can easily default a value if it is null by doing the following:

string fileName = tempFileName ?? "Untitled";

Very useful - I always prefer to write one line of code rather than many the above is much nicer than:

string fileName = tempFileName != null ?
                                 tempFileName : "Untitled";

This is a nice article about this subject: http://davidhayden.com/blog/dave/archive/2006/07/05/NullCoalescingOperator.aspx

Posted Tuesday, July 15th, 2008 at 12:38 pm
Filed Under Category: Uncategorized
Responses are currently closed, but you can trackback from your own site.

0

Comments are closed.