Reputation: 77298
And why would I use one over the other in my code?
Upvotes: 18
Views: 4419
Reputation:
In .NET 4.0 Beta 1 RuntimeTypeHandle
just wraps RuntimeType
.
It seems all benefits of using it as a cheap Type
proxy have gone.
System.RuntimeTypeHandle
type shows that this type is indeed only a wrapper around System.RuntimeType
these days. RuntimeTypeHandle
are gone in .NET 4.Upvotes: 7
Reputation: 32047
Caution: This answer appears to be out of date. It was posted before .NET 4 became available, which apparently introduced some optimizations regarding
Type
and thus rendered the information in this answer obsolete. See this more recent answer for details.
According to this blog post (from 2006) by Vance Morrison, RuntimeTypeHandle
is a value type (struct
) that wraps an unmanaged pointer, so Type.GetTypeHandle(obj).Equals(anotherHandle)
is faster to use for strict "is exactly the same type" comparisons than obj.GetType().Equals(anotherType)
— the latter creates System.Type
instances which are, apparently, heavier.
However, it's also less obvious, and definitely falls under the category "micro-optimization" so if you're wondering when you need one over the other, you should probably just use System.Type.
Upvotes: 12