VB.NET:获取实例的类名

时间:2023-01-15 17:01:06

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

有没有办法用VB.NET获取实例的类名?

3 个解决方案

#1


17  

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.

全名将为您提供Type的完全限定名称,包括Type的名称空间。

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

有关Type可用内容的更多信息,请参阅MSDN。

#2


15  

Try the following

请尝试以下方法

Dim name = Me.GetType().Name

Or for any instance

或者对于任何实例

Dim name = theObject.GetType().Name

#3


1  

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

当您使用asp.net网站类而非对象时,这可能会更好。

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

OR

要么

when you are using desktop app.

当您使用桌面应用程序时。

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

#1


17  

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.

全名将为您提供Type的完全限定名称,包括Type的名称空间。

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

有关Type可用内容的更多信息,请参阅MSDN。

#2


15  

Try the following

请尝试以下方法

Dim name = Me.GetType().Name

Or for any instance

或者对于任何实例

Dim name = theObject.GetType().Name

#3


1  

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

当您使用asp.net网站类而非对象时,这可能会更好。

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

OR

要么

when you are using desktop app.

当您使用桌面应用程序时。

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