DirectCast の 2 つの使用例を次に示します。1 つは実行時に失敗し、もう 1 つは成功します。
Dim q As Object = 2.37
Dim i As Integer = CType(q, Integer)
' The following conversion fails at run time
Dim j As Integer = DirectCast(q, Integer)
Dim f As New System.Windows.Forms.Form
Dim c As System.Windows.Forms.Control
' The following conversion succeeds.
c = DirectCast(f, System.Windows.Forms.Control)
この例では、q のランタイム型は倍精度浮動小数点数型 (Double) です。Double は Integer に変換可能なので、CType は成功します。しかし、最初の DirectCast は実行時に失敗します。Double のランタイム型は Integer に変換可能ですが、継承の関係にはないからです。2 番目の DirectCast は、Form 型から Control 型への変換です。Form は Control を継承しているので成功します。