The GetType Keyword
Each time you create an instance of a class, the .NET runtime creates an instance behind the scenes of the System.Type
class that represents your object. In.NET development you have the ability to inspect instances of the System.Type
class (known as reflection) at runtime and to get a reference to that System.Type
. The Visual Basic programming language offers the GetType
keyword, which enables you to accomplish both tasks. The GetType
keyword has two different behaviors: First, it is an operator, and second, it is a method. GetType
is typically used to compare two instances of an object or to access metadata of a type at runtime. To understand GetType
, we’ll look at a few examples. Consider this first code snippet:
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.