Implicit casting in VB.NET

Posted by Shimmy on Stack Overflow See other posts from Stack Overflow or by Shimmy
Published on 2010-04-12T02:43:11Z Indexed on 2010/04/12 2:53 UTC
Read the original article Hit count: 759

The question is intended for lazy VB programmers. Please.

In vb I can do and I won't get any errors.

Example 1

Dim x As String = 5
Dim y As Integer = "5"
Dim b As Boolean = "True"

Example 2

Dim a As EnumType = 4
Dim v As Integer = EnumType.EnumValue

Example 3

Private Sub ButtonClick(sender As Object, e As EventArgs)
    Dim btn As Button = sender        
End Sub

Example 4

Private Sub ButtonClick(sender As Button, e As EventArgs)
    Dim data As Contact = sender.Tag
End Sub

If I surely know the expected runtime type, is this 'forbidden' to rely on the vb-language built-in casting? When can I rely?

Thanks

© Stack Overflow or respective owner

Related posts about vb

Related posts about vb.net