Nullable type to string function
I just answered a thread where somebody wanted to know how to take any nullable type, check if it's value is null, and depending on that either return String.Empty or ToString. Here's how you do that:
public
static
string
ConvertNullableToString(T? value)
where
T :
struct
{
return
value.ToString() ??
String
.Empty;
}
int
? value1 =
null
;
int
? value2 = 9;
string
stringValue1 = ConvertNullableToString<
int
>(value1);
string
stringValue2 = ConvertNullableToString<
int
>(value2);