about operator

自定义类 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

'

'

'

'--------------------------------------------------------------------

 

‘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

 '
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值