Dim c as New Circle
If TypeOf c Is Shape Then _
Console.WriteLine("c is a Shape")

Type Conversion / Casting
Dim d As Single = 3.5
Dim i As Integer = CType(d, Integer) '
set to 4 (Banker's rounding)
i = CInt(d) ' same result as
CType
i = Int(d) ' set to 3 (Int function
truncates the decimal)

Dim obj As Object = New SuperHero
If TypeOf obj Is SuperHero Then _
Console.WriteLine("Is a SuperHero object.")

' Mark object for quick disposalUsing reader As StreamReader = File.OpenText("test.txt")
Dim line As String = reader.ReadLine()
While Not line Is Nothing
Console.WriteLine(line)
line = reader.ReadLine()
End WhileEnd Using

' Subroutine can display any type of List
Sub DisplayList(Of T)(ByVal list As List(Of T))
For Each item As T In list
Console.WriteLine(item)
Next
End Sub

' Class works on any data type
Class SillyList(Of T)
Private list(10) As T
Private rand As New Random

Public Sub Add(ByVal item As T)
list(rand.Next(10)) = item
End Sub

Public Function GetItem() As T
Return list(rand.Next(10))
End Function
End Class

' Limit T to only types that implement
IComparable
Function Maximum(Of T As IComparable)(ByVal ParamArray items As
T()) As T
Dim max As T = items(0)
For Each item As T In items
If item.CompareTo(max) > 0 Then max = item
Next
Return max
End Function

' Read all lines from text file
Dim reader As StreamReader = File.OpenText("c:myfile.txt")
Dim line As String = reader.ReadLine()
While Not line Is Nothing
Console.WriteLine(line)
line = reader.ReadLine()
End While
reader.Close()