Reputation: 4090
What is the fastest way to see if to objects are of the same type?
I'm now using obj1.GetType.Equals(obj2.GetType)
but I'm hoping there is a faster way.
Upvotes: 0
Views: 711
Reputation: 1761
Well, this way is the fastest :)
But you can write:
If obj1.GetType Is obj2.GetType Then
End If
Upvotes: 4
Reputation: 8280
Note, I only know C#, but hopefully the idea will help
Alternatively you could do:
obj1.GetType() == obj2.GetType()
Additionally, if you find yourself using this a lot, you could make an extension method. Like so
public static bool IsSameTypeAs(this object source, object comparator)
{
return source.GetType().Equals(comparator.GetType();
}
// usage
obj1.IsSameTypeAs(obj2)
Upvotes: 0