Tip of the day: Using the null-coalescing operator over the conditional operator

I’ve recently been refactoring a lot of code that used the conditional operator and looked something like this: int someValue = myEntity.SomeNullableValue.HasValue ? myEntity.SomeNullableValue.Value : 0; That might seem less verbose than the traditional alternative, which looks like this: int someValue = 0; if (myEntity.SomeNullableValue.HasValue) someValue = myEntity.SomeNullableValue.Value; …or other variations on that theme. However, …

The simplicity of nullable types

I just discovered nullable types. Wow! They are really simple and such a powerful feature. Just see for yourself…. If you have an int or a DateTime or any other value type you’ll already know that you cannot assign null to them. But in C#2.0 you can. You can define a nullable int by adding …