Implicit casting in VB.NET
The question is for lazy VB programmers. You are welcome.
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 know exactly the expected runtime type, is it "forbidden" to rely on inline casting in vb? When can I rely?
source to share
The irony of lazy practices like this is that they often end up costing you more time in the long run. Can you really be absolutely certain that your inputs will always be in a format that can be automatically applied to the intended type under any circumstance and across all locales?
Pondering all the possible ramifications and handling almost inevitable errors will probably take more time than just strictly typing your variables, strictly checking your inputs, and explicitly throwing where needed.
source to share