开发者

How can i get the type name value of an object as a string?

开发者 https://www.devze.com 2023-04-12 08:28 出处:网络
I know it\'s simple.I can\'t find it any where. I want something like: string MyString = object.GetType;

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;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号