Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
 GetType Operator
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Basic Language Reference
GetType Operator

Updated: November 2007

Returns a Type object for the specified type. The Type object provides information about the type such as its properties, methods, and events.

GetType(typename)
typename

The name of the type for which you desire information.

The GetType operator returns the Type object for the specified typename. You can pass the name of any defined type in typename. This includes the following:

  • Any Visual Basic data type, such as Boolean or Date.

  • Any .NET Framework class, structure, module, or interface, such as System..::.ArgumentException or System..::.Double.

  • Any class, structure, module, or interface defined by your application.

  • Any array defined by your application.

  • Any delegate defined by your application.

  • Any enumeration defined by Visual Basic, the .NET Framework, or your application.

If you want to get the type object of an object variable, use the Type..::.GetType method.

The GetType operator can be useful in the following circumstances:

  • You must access the metadata for a type at run time. The Type object supplies metadata such as type members and deployment information. You need this, for example, to reflect over an assembly. For more information, see System.Reflection.

  • You want to compare two object references to see if they refer to instances of the same type. If they do, GetType returns references to the same Type object.

The following examples show the GetType operator in use.

Visual Basic
' The following statement returns the Type object for Integer.
MsgBox(GetType(Integer).ToString())
' The following statement returns the Type object for one-dimensional string arrays.
MsgBox(GetType(String()).ToString())

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker