How can i get the type name value of an object as a string?
I know it's simple. I can't find it any where.
I want something like:
string MyString = object.GetType;
I know that it wont work as written but how do I get the type value into a string.
Thanks for your indulgence, Charle开发者_运维问答s
How about this?
string myString = object.GetType().ToString();
There are a few properties. If you have the studio, the intellisense should give you what you want.
You can try also:
string myString = myObj.GetType().Name;
string myString2 = myObj.GetType().Fullname; // Should give you the full type name including namespace
If you know the compile-time type of the object:
string myString = typeof(object).Name;
If you need to use the runtime type of an object:
string myString = someInstance.GetType().Name;
精彩评论