对于VB.NET语法规则的理解,是掌握这一编程语言的首要技巧。如何才能正确的掌握这一规则呢。首先让我们从文章中给出的几个案例来详细的分析它的主要概念,从而加深我们对这一规则的理解程度。
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) ''Message
Box.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
VB.NET语法规则的一些案例讲解就为大家介绍到这里啦。
【编辑推荐】