开发者

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;

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜