VB.NET learning notes (variable survival and assignment)

zhaozj2021-02-16  50

Variable has a survival cycle

This programmer knows that a modified shared is added to VB.NET. Shared Keywords Indicates one or more declared programming elements will be shared. The point is: the shared element is not a particular instance of a certain or structure. It is necessary to qualify the shared element to access them by using the variable name of the specific instance of the class name or structure name or a specific instance of the class or structure. A simple description is that the Shared variable is for type itself instead of serving a specific object.

Shared example

Public Class Testa

Public Shared I as INT32 = 10

END CLASS

Public Class TestB

Inherits Testa 'inherits Testa

Public Sub New ()

Testa.i = 100 'uses the name of the name to access Shared variables

End Sub

END CLASS

It should be noted that the relationship between Shared variables and types and instances in VB.NET requires not particularly strict syntax, and the programmer can use the type of instance to access and modify the shared variable, but it is very strict in C #. .

Assigning statement

Assign the value in VB.NET divided into: Simple assignment statement, composite assignment statement, delegate assignment statement, MID assignment statement.

Simple assignment statement

Simple assignment statements and previous VB assignment statements are basically not very different, but now VB.NET allows immediate assignments to the variable declaration (examples can be seen in front of the front accessibility). We need to pay attention to the declarations and assignment methods of arrays.

In VB.NET, you can describe the latitude and upper limits of the array when declaring array, and the lower limit of the latitude of each array is 0, and cannot be changed. However, "zero length array" can be specified by specifying the upper limit of the array as -1. This array does not contain any elements.

If you do not display the length of the array, you can assign a value immediately on the declaration array.

An array of statements and assignments

Public Class Testa

DIM IARR () AS INT32

DIM Barr (5) as boolean '5 refers to the upper limit of the Barr subscript, that is, 6 elements

Dim larr () as long = new long (3) {100, 200, 300, 400}

DIM Carr () as string = new string () {"a", "b", "c"}

DIM DARR (-1) As Double

END CLASS

About more characteristics of the array, will be described in detail in the introduction of the array.

Composite assignment

Now VB.NET begins to support composite assignment statements. Unlike the fully expanded expression, the variable on the left side of the composite assignment statement is only calculated once. This means that at runtime, the variable expression is calculated on the right side of the right side of the assignment statement.

Composite assignment

Public Class Testa

Public Sub New ()

DIM I as Int32

i = 10

End Sub

END CLASS

MID assignment

The MID assignment is actually the processing assignment process of the string. A method of assignment of the MID can be understood by the following examples.

MID example

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 TOEND SUB

END CLASS

Keywords on the entrusted statement

Addressof

A detailed description is described in later commission and events.

转载请注明原文地址:https://www.9cbs.com/read-27046.html

New Post(0)