VB.NET语法规则很多,在这里给大家分享一下我总结一点经验,列举了3个实例,希望可以能让大家深入的了解语法规则的规律。
VB.NET语法规则实例1:
同 Integer 类型的变量比较
- Public Class CompareForm
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim A As Integer = 10
- Dim B As Integer = 20
- If A <= B Then
- MessageBox.Show("提示:A<=B")
- Else
- MessageBox.Show("提示:A>B")
- End If
- End Sub
- End Class
VB.NET语法规则实例2:
Boolean变量的比较
- ublic Class LogicForm
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim a As Boolean = True
- Dim b As Boolean = False
- If a And b = True Then ''和If a And b Then相同
- MessageBox.Show("提示:a和b都是True ")
- Else
- MessageBox.Show("提示:a和b有一个不是True ")
- End If
- End Sub
- End Class
VB.NET语法规则实例3:
同String类型变量比较 String和Integer不同变量的比较
- Public Class StrForm
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim str1, str2 As String
- str1 = "Hello"
- str2 = "World"
- MessageBox.Show("提示:" & str1 + " " + str2) ''MessageBox.show(str1 & " " & str2)也可以
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim z As Integer
- Dim x As String = " 100"
- z = 50
- MessageBox.Show(x & z) '' MessageBox.Show(x + z)
- End Sub
- End Class
【编辑推荐】