Geeks With Blogs
Hannes Pavelka It isn't rocket science. Well, unless of course you're NASA September 2006 Entries
A smart way to do null comparison in csharp
C# 2.0 offers a new null coalescing operator: ?? You can look it up in C# Language Specification ( ?? Operator “take the first value if it is not null, otherwise the second.”I consider this a pretty smart way to do some null comparision where you would usually use an if==null construct. Here is a quick example: string user = “Hannes”; = user ?? “unkown”;This will set Foo.Bar to “Hannes”.int? x = null;int? y = 2;int result = x ?? y;This will set result to 2;The operator works ......

Posted On Tuesday, September 5, 2006 3:19 AM

Copyright © Hannes Pavelka | Powered by: