‘自定义类 dog
Public Class dogClass dog
Private s_name As String
Private s_color As Color
Private s_age As Integer
Public Sub New()Sub New()
s_name = "塞北的雪"
s_age = 22
s_color = System.Drawing.Color.Red
End Sub
Public Property Name() As String
Get
Return s_name
End Get
Set(ByVal value As String)
s_name = value
End Set
End Property
Public Property Color()Property Color() As Color
Get
Return s_color
End Get
Set(ByVal value As Color)
s_color = value
End Set
End Property
Public Property Age()Property Age() As Integer
Get
Return s_age
End Get
Set(ByVal value As Integer)
s_age = value
End Set
End Property
Public Shared Operator +(ByVal a As dog, ByVal b As dog)
Dim c As New dog
c.Name = a.Name + b.Name
c.Age = a.Age + b.Age
c.Color = Color.FromArgb((a.Color.ToArgb + b.Color.ToArgb) / 2)
Return c
End Operator
End Class
Dim sb As New System.Text.StringBuilder
Dim m As New dog
Dim n As New dog
Dim c As dog
m.Name = "NorthSnow"
m.age=22
c = m + n
sb.AppendLine()
sb.Append(m.Name)
sb.Append("--")
sb.Append(m.Age)
sb.Append("--")
sb.Append(m.Color.ToArgb)
sb.AppendLine()
sb.Append(n.Name)
sb.Append("--")
sb.Append(n.Age)
sb.Append("--")
sb.Append(n.Color.ToArgb)
sb.AppendLine()
sb.Append(c.Name)
sb.Append("--")
sb.Append(c.Age)
sb.Append("--")
sb.Append(c.Color.ToArgb)
MsgBox(sb.ToString)
'result display as follow
'NorthSnow--22---65536
'塞北的雪--22---65536
'NorthSnow塞北的雪--44---65536
'
'
'--------------------------------------------------------------------
‘Is运算符比较两个引用对象是否引用了同一实例
Dim a As New dog
Dim b As New dog()
If a Is b Then
MsgBox("True")
Else
MsgBox("False")
End If 'false
b = a
b.Name = "NorthSnow"
If a Is b Then
MsgBox("True")
Else
MsgBox("false")
End If 'true
'
'
'
'--------------------------------------------------------------------
'
''--------------------------------------------------------------------
'like 操作符用于判断一个字符串与另外一个字符串是否匹配,大小写敏感。
Dim a As String = "Northsnow,塞北的雪"
Dim b As String = "Northsnow,塞北的雪"
If a Like b Then
MsgBox("true")
Else
MsgBox("false")
End If 'true
b = "northsnow,塞北的雪"
If a Like b Then
MsgBox("true")
Else
MsgBox("false")
End If 'false
'
'
like操作符支持的通配符共有5种:
? 表示一个任意字符(1个)
* 任意个任意字符(0-n个)
# 表示一个数字
[charlist] 表示 charlist 中的任意一个字符
[!charlist] 表示 不在charlist 中的任意一个字符
Dim a As String = "Northsnow.123"
Dim b As String = "*.###"
MsgBox(a Like b) 'True
a = "Northsnow.123"
b = "[A-Z][a-z]*#"
MsgBox(a Like b) 'True
a = "Northsnow.123"
b = "[A-Z][a-z]*[a-z]"
MsgBox(a Like b) 'False
a = "Northsnow.123"
b = "[A-Z][a-z]*[0-9]"
MsgBox(a Like b) 'True
'
'
'
''--------------------------------------------------------------------
TypeOf 返回当前对象的类型,每一个类都有一个getType方法与它很相似
Dim a As New dog
Dim b As New dog
Dim c As Type
c = a.GetType
MsgBox(c.ToString) 'vb1.Form7.dog
If TypeOf (a) Is vb1.Form7.dog Then
MsgBox(True)
End If 'True
'