Hi all,
I used C# before. However, after I joined in a new company, I need to write vb.net. However I find very difficult to write it. Because I found that vb.net is not strong-typed. It is really not strong-typed? Or any settings for that? Here are examples.
If (Me.Check1() And Me.Check2()) Then
From my C# knowledge, once Me.Check1()
returns false, Me.Check2()
will not be executed. However I was wrong. And
is for bitwise operations. I should use AndAlso
for boolean operations. So it should be
If (Me.Check1() AndAlso Me.Check2()) Then
The problem is that If (Me.Check1() And Me.Check2()) Then
is still valid and no compilation error. I really want to know if I am able to check such "inappropriate" operations.
And
and AndAlso
is just one of the cases.
Sometimes, I need to do ignore cases string comparisons. However, everyone makes mistakes. Sometimes, I did
If (String.Compare(Me.string1, Me.string2, True)) Then
I think everyone knows the problem. It should be
If (String.Compare(Me.string1, Me.string2, True) = 0) Then
However, I still cannot check such case during compilation.
I love C# because it helps us to find many problems during compilation. However, VB.NET makes me very confused and many errors must be determined during run-time and testing.
One more example is that
Public Sub MySub(ByVal obj as Object)
Console.WriteLine(obj.MyProperty)
End Sub
In vb.net, this kind of statement is still valid. Why? Why? Why? Does anyone know how to use vb.net like C#?