R
rubikzube*
Hi.
I'm trying to write a snippet of code to detect if a variable is a
nullable<t> struct, and I can't figure out the right syntax or if such
a thing is even possible... Below are the results that I got when I
attempted to perform some simple tests.
Nullable<int> i = 32;
bool isNullableClass = i is Nullable; // false
bool isNullableStructInt = i is Nullable<int>; //true
bool isValueType = i is ValueType; // true
bool isNullableStruct = i is Nullable<>; // doesn't compile b/c must
provide a struct
bool isNullableStructValueType = i is Nullable<ValueType>; // doesn't
compile because ValueType is not a struct
System.Type iType = i.GetType(); // returns System.Int32
I also tried reflecting through the code and walking through the
documentation, but there doesn't seem to be any method of detecting if
a variable is a nullable struct. Does anyone know how to do this?
I'm trying to write a snippet of code to detect if a variable is a
nullable<t> struct, and I can't figure out the right syntax or if such
a thing is even possible... Below are the results that I got when I
attempted to perform some simple tests.
Nullable<int> i = 32;
bool isNullableClass = i is Nullable; // false
bool isNullableStructInt = i is Nullable<int>; //true
bool isValueType = i is ValueType; // true
bool isNullableStruct = i is Nullable<>; // doesn't compile b/c must
provide a struct
bool isNullableStructValueType = i is Nullable<ValueType>; // doesn't
compile because ValueType is not a struct
System.Type iType = i.GetType(); // returns System.Int32
I also tried reflecting through the code and walking through the
documentation, but there doesn't seem to be any method of detecting if
a variable is a nullable struct. Does anyone know how to do this?