Null-Coalescing Operator
While at a rather disappointing MSDN event yesterday, I came across one gem of C# 3.0 candy in the form of a null-coalescing operator. This is basically a short-cut for the oft seen:
string emailAddress = parsedValue != null ? parsedValue : "(Not provided)";
OR
string emailAddress = String.Empty;
if (parsedValue != null) {
emailAddress = parsedValue;
}
else {
emailAddress = "(Not provided)";
}
Using the Null-Coalescing Operator
These can now instead be re-written using the new null-coalescing operator as:
string emailAddress = parsedValue ?? "(Not provided)";
This can roughly be read as "Set emailAddress equal to parsedValue unless it is null, in which case set it to the literal (Not Provided)"....
Using Anonymous Method Predicates to Search Lists
I use System.Collections.Generic.List all over the place. Generics are a couple of years out of date and most people are done with them in terms of cool factor, but that doesn't in any way detract from the coolness they add to my life each and every day. I still eat toast and that's been around for ages. I answered a question this morning that made me realize that while the generic list class has been generally embraced by most, it perhaps has also been generally muddled by some attempting to keep up with the oft quick pace that is .NET. I've seen quite a...