VB.NET: Get class name of a instance

爷,独闯天下 提交于 2019-12-08 14:32:15

问题


Is there a way to get the instance's class name with VB.NET?


回答1:


Dim type As Type = yourObject.GetType()
Dim typeName As String = type.FullName

Full name will get you the fully qualified name of the Type, including the namespace of the Type.

See MSDN for more information on what is available with Type.




回答2:


Try the following

Dim name = Me.GetType().Name

Or for any instance

Dim name = theObject.GetType().Name



回答3:


This could be better when you are using asp.net website class not object.

Dim ClassName as string = Me.GetType().BaseType.FullName

OR

when you are using desktop app.

Dim ClassName as string = Me.GetType().Name


来源:https://stackoverflow.com/questions/3533774/vb-net-get-class-name-of-a-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!