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

How to realize Array assignment by VB.NET

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces VB.NET how to achieve array assignment, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

A decorated Shared has been added to the VB.NET array assignment. The Shared keyword indicates that one or more declared programming elements will be shared.

The point is that shared elements are not associated with a specific instance of a class or structure. You need to access shared elements by using the class name or structure name or the variable name of a specific instance of the class or structure to qualify the shared elements. The simple description is that the Shared variable serves the type itself, not a specific object.

An example of Shared

Public Class TestA

Public Shared i As Int32 = 10

End Class

Public Class TestB

Inherits TestA 'inherits TestA

Public Sub New ()

TestA.i = 100

'use the name of the type to access the Shared variable

End Sub

End Class

It is important to note that in VB.NET, the syntax of Shared variables in relation to types and instances does not seem to be particularly strict. Programmers can use instances of types to access and modify Shared variables, but they are very strict in C #.

VB.NET array assignment statement

Assignment statements in VB.NET are divided into simple assignment statements, compound assignment statements, delegation assignment statements and Mid assignment statements.

Simple VB.NET array assignment statement

Simple assignment statements are basically not much different from previous VB assignment statements, except that VB.NET now allows you to assign values immediately after a variable is declared (you can see the example in the previous accessibility example). What we need to focus on is the declaration and assignment of the array.

In VB.NET, when you declare an array, you can describe both the latitude and the upper limit of the array, and the lower limit of the latitude of each array is 0, which cannot be changed. However, you can specify a zero-length array by specifying the upper limit of the array to-1. This array does not contain any elements.

If the length of the array is not displayed, you can assign a value immediately while declaring the array.

Examples of declaration and assignment of array

Public Class TestA

Dim iArr () As Int32

Dim bArr (5) As Boolean

'5 refers to the upper limit of the bArr subscript, that is, there can be 6 elements

Dim lArr () As Long =

New Long (3) {100,200,300400}

Dim cArr () As String =

New String () {"A", "B", "C"}

Dim dArr (- 1) As Double

End Class

Compound assignment

Now VB.NET starts to support compound assignment statements. Unlike a fully expanded expression, the variable to the left of the compound assignment statement is evaluated only once. This means that at run time, the variable expression evaluates before the expression to the right of the assignment statement.

An example of compound assignment

Public Class TestA Public Sub New () Dim i As Int32 I + = 10 End Sub End Class

Mid assignment

Mid assignment is actually the process of string assignment. You can understand how Mid is assigned through the following examples.

An example of Mid

Public Class TestA

Public Sub New ()

Dim TmpStr As String

TmpStr = "Hello VB.NET"

'Hello VB.NET

Mid (TmpStr, 7, 2) = "c #"

'Hello c#.Net

Mid (TmpStr, 7) = "VB6"

'Hello VB6Net

Mid (TmpStr, 7) = "VB6 to

VB.NET "'Hello VB6 to

Mid (TmpStr, 7, 3) = "VB6

To VB.NET "'Hello VB6 to

End Sub

End Class

Thank you for reading this article carefully. I hope the article "how to achieve array assignment in VB.NET" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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