GetType from object is returning RuntimeType

If you call it like this -

string a = "";
string type = getType(a);

It will return System.String

But if you call like this -

string a = "";
string type = getType(a.GetType());

Then it will return System.RuntimeType

Also, there is small typo in your method -

Type type = obj.getType(); should be Type type = obj.GetType();


I guess you called it like this: getType(typeof(string)). typeof(abc) is a value of type Type (or RuntimeType which is an implementation detail).

Call it like this:

getType("")

Tags:

C#