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:
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access