I’ve been trying to be more consistent lately with my blog entries, making at least one a day during the Monday through Friday work week. Well, that has sort of kind of maybe not really worked out too hot yet. But as I sat and thought, while reading through some blogs, I stumbled on Stuart Thompson’s blog where he mentions Null-Coalescing Operators. These suckers are great!
Per the example on his site, what we used to type when checking for nulls appeared something like this:
1 namespace SomeNamespace
3 public class Coalescing
5 private string emailAddress = string.Empty;
6 private string parsedValue = string.Empty;
8 public string CheckForParsedValue()
10 if (parsedValue != null)
12 emailAddress = parsedValue;
16 emailAddress = “(Not provided)”;
19 return emailAddress;
but now will be coded in a super awesome elite looking way of:
10 string emailAddress = parsedValue ?? “(Not provided)”;
I’m stoked personally, and I think this makes a great tip o’ the day! Of course it is kind of a “future” tip o’ the day. Thanks Stuart pointing out this interesting tidbit of future C# coolness.