I'm working on a switch statement with Type checking. The following code is working perfectly well for all the types, but, the challenge is with Nullable types.
switch (Type.GetTypeCode( propertyInfos.PropertyType))
{
// Type code doesn't have reference with int, long, etc.,
case TypeCode.DateTime:
// Do the work for DateTime
break;
case TypeCode.Int32 :
// Do the work for Int32
break;
case TypeCode.Int64:
// Do the work for long
break;
case TypeCode.DateTime? :
break;
default:
break;
}
I have tried that to change as GetType
and DateTime.Today.GetType().ToString()
would give us System.DateTime as a string. But, when used the compiler throws error as that is not a valid Constant string
. At any given time instance, DateTime.Today.GetType()
would always gives us System.DateTime
, why this is not accepted by compiler?