Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the VB.NET operators

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the VB.NET operators", which is easy to understand and clear, hoping to help you solve your doubts. Let the editor lead you to study and learn this article "what are the VB.NET operators?"

A custom class, dog, will be used in this article, with the following code:

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 = "Snow in Saibei" s_age = 22 s_color = System.Drawing.Color.Red End Sub Public Property Name () Property Name () As String Get Return s_name End Get Set (ByVal value As String) s_name = valueEnd SetEnd Property Public Property Color () Property Color () As Color Get Return s_color End Get Set (ByVal value As Color) s _ Color = valueEnd Set End PropertyPublic Property Age () Property Age () As IntegerGetReturn s_age End GetSet (ByVal value As Integer) s_age = valueEnd Set End PropertyPublic Shared Operator + (ByVal an As dog ByVal b As dog) Dim c As New dogc.Name = a.Name + b.Namec.Age = a.Age + b.Agec.Color = Color.FromArgb ((a.Color.ToArgb + b.Color.ToArgb) / 2) Return cEnd OperatorEnd Class

1. Is operator

The Is operator compares whether two reference objects refer to the same instance. Examples are as follows:

Dim an As New dog Dim b As New dog () If an Is b Then MsgBox ("True") Else MsgBox ("False") End Ifb = ab.Name = "North Snow" If an Is b Then MsgBox ("True") Else MsgBox ("false") End If'false'true

2. VB.NET operator overload

We can overload the operator as needed, and the dog class in this article overloads the + operator. When adding two dog classes, an instance of dog class is returned. His Name is the sum of the names of the two dog instances, the age is also the sum of the ages of the dog instances, and the color is the average of the two colors. Examples are as follows:

Dim sb As New System.Text.StringBuilder Dim m As New dogDim n As New dogDim c As dogm.Name = "NorthSnow" 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) 'NorthSnow--22---65536' Snow in the North-- Snow in the North of 22---65536'NorthSnow Saibei

3. Like operator

The like operator, which is case sensitive, is used to determine whether one string matches another. The syntax is Result=String like Pattern.

Examples are as follows:

Dim an As String = "Northsnow, Saibei snow" Dim b As String = "Northsnow, Saibei snow" If a Like b ThenMsgBox ("true") ElseMsgBox ("false") End Ifb = "northsnow, Saibei snow" If a Like b ThenMsgBox ("true") ElseMsgBox ("false") End If'true'false

In addition, Pattern supports wildcards. This certainly reminds us of regular expressions (Regular Expression). However, we must not be confused, although some places are similar, but some wildcards are different from regular expressions, and their functions are also different. There are five wildcards supported by the like operator:

◆? Represents an arbitrary character (1)

◆ * any character (0murn)

◆ # represents a number

◆ [charlist] represents any character in charlist

◆ [! charlist] represents any character that is not in the charlist

Friends who have used regularities will be easy to understand. There are a few core rules that must be kept in mind, that is:

(1) * can match any string

(2)? Can match any character

(3) and # equals [0-9] can only match one number. If you want to match two numbers, you need to write as # #

(4) the characters in the character list can be used to provide an interval to simplify writing.

(5) case sensitivity

Here are a few examples:

Dim an As String = "Northsnow.123" Dim b As String = "*. #" MsgBox (a Like b) 'Truea = "Northsnow.123" b = "[Amurz] [Amurz] * #" MsgBox (a Like b)' Truea = "Northsnow.123" b = "[Amurz] [Amurz] * [Amurz]" MsgBox (a Like b) 'Falsea = "Northsnow.123" b = "[Amurz] [aMuz] * [0-9]" MsgBox (a Like b)' True

4. Other special VB.NET operators

AndAlse,OrElse is similar to and and or, except that they are smarter than the latter, and when the previous judgment has determined the return value, the value of the latter expression is no longer evaluated.

TypeOf returns the type of the current object, and each class has a getType method that is similar to it. A small example is as follows:

Dim an As New dogDim b As New dogDim c As Typec = a.GetTypeMsgBox (c.ToString) If TypeOf (a) Is vb1.Form7.dog ThenMsgBox (True) End If'vb1.Form7+dog'True is all the content of the article "what are the VB.NET operators?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report