Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my view,they have same performance.
Posted

1 solution

Underlying implementation will probably give the answer. Let's do it then, GetType() method and UnderlyingSystemType is from Type class from System namespace of the mscorlib.dll assembly. GetType() method has a implementation in the Type class with following implementation (based on the IL code extracted from ILDasm tools)
C#
public static Type GetType(string typeName)
{
    StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;
    return RuntimeType.GetType(typeName, false, false, false, ref lookForMyCaller);
}

we need to dive deeper into this method, if we look the implementation if the GetType(.....) of the RuntimeType class we can see behind the scene it is returning the RuntimType itself as,
C#
internal static RuntimeType GetType(string typeName, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark)
{
    return RuntimeTypeHandle.GetTypeByName(typeName, throwOnError, ignoreCase, reflectionOnly, ref stackMark, false);
}

and the GetTypeByName method,
C#
internal static RuntimeType GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref StackCrawlMark stackMark, bool loadTypeFromPartialName)
{
    RuntimeType o = null;
    GetTypeByName(name, throwOnError, ignoreCase, reflectionOnly, JitHelpers.GetStackCrawlMarkHandle(ref stackMark), loadTypeFromPartialName, JitHelpers.GetObjectHandleOnStack<RuntimeType>(ref o));
    return o;
}

but UnderlyingSystemType is marked as abstract property with the following implementation,
C#
public abstract Type UnderlyingSystemType { get; }

This property has a implementation in the RuntimeType class in which is,
C#
public override Type UnderlyingSystemType
{
    get
    {
        return this;
    }
}

So the both return the RuntimeType object as result. Hope it shows the internal of the GetType() and UnderlyingSystemType :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900