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 that typeof(T) uses System.Type::GetTypeFromHandle(RuntimeTypeHandle handle)
, and the other is just plain System.Object::GetType()
. The implementations are [MethodImpl(MethodImplOptions.InternalCall)]
,
so the methods are defined in native code in the CLR. So, I'm just wondering if anyone is aware of any reason to prefer one over the other?
EDIT: Let me clarify, I'm mostly interested in the cases where it doesn't seem to matter which you choose - that is, is there a performance difference, or any other reason? Thanks!