So I have been intrigued by the ?? operator, but have still been unable to use it. I usually think about it when I am doing something like:
var x = (someObje
I use the null-coalescing operator often when parsing strings into other data types. I have a set of extension methods that wrap things like Int32.TryParse and return a nullable int instead of exposing an output parameter to the rest of my code. Then I can parse a string and provide a default value if the parse failed, in a single line of code.
// ToNullableInt(), is an extension method on string that returns null
// if the input is null and returns null if Int32.TryParse fails.
int startPage = Request.QueryString["start"].ToNullableInt() ?? 0;