December 24, 2010

Coalescing (??) Operator for .Net

The Null-Coalescing Operator acts similiar to TSQL IsNull.

The ?? operator defines the default value to be returned when a nullable type is assgned to a non-nullable type. This works for both reference types and value types

C#.Net Example:
string message = strOldMessage ?? "This is the default";
TSQL Example:
IsNull(printDate, GetDate())

No comments:

Post a Comment