Is anyone aware of any differences between typeof(T) where T : struct
,
for example, vs. t.GetType() where t is a System.Object
?
ILdasm shows t
Well, sometimes in generic code, you know the compile time type from a type parameter T
, without having an instance. Then you must use typeof(T)
.
At other times, typically in non generic code, you might be interested in the runtime type of an object. Then you use GetType()
.
So in some cases, depending on what you want to know, or what you can query for, you only have one option.
And sometimes, you could choose.