Comparing typeof(Type) to System.RuntimeType
Solution 1:
Consider Type
is a normal class.
Type t1 = typeof(string);
Type t2 = "1".GetType();
There's no difference between t1
and t2
. And What is t1
? Just consider t1
or t2
as a normal object and the type of the object is System.Type
. It means that t1
or t2
nearly equals new Type("System.String")
.
How can I know an object obj
is aStringBuilder
?
Just use is
or as
:
bool objIsStringBuilder = obj is StringBuilder;
How can I know t1
is a Type
?
In the same way:
bool t1IsType = t1 is Type;
What is typeof(Type)
or t1.GetType()
?
Type t3 = typeof(Type);
Then t3
is nearly equals new Type("System.Type")
. So of course t1
and t3
are not equal.