Get the rank (dimension) and dimensions of the array in VB.NET

zhaozj2021-02-12  211

[The following resources come from MSDN]

Array.Rank attribute

Get the rank (dimension) of Array.

Array.getupperbound method

Get the upper limit of the specified dimension of Array.

Array.Length attribute

A 32-bit integer is obtained, which indicates the total number of elements in all dimensions of Array.

Array.createInstance method

New instances of initializing the Array class

E.G. Dim A (20, 30, 40) AS INT32 Messagebox.Show (a.rank) '3 MessageBox.show (A.GetupperBound (1)) '20 MessageBox.show (a.length)' 26691

Dim Arr as array = array.createInstance (Gettype (INT32), 2, 3, 4, 5, 6) Arr.SetValue (2004, 1, 2, 3, 4) MessageBox.show (Arr.GetValue (1, 2, 3, 4, 5)) '2004

[Note] Unlike most classes, Array provides CREATEINSTANCE methods to allow late binding access, rather than providing public constructors. Dim arrok as array arrok = array.createInstance (Gettype (String), 4, 5) MessageBox.Show (arrok.rank) '2

'The following is a wrong DIM ARRERR AS ARRAY ARRERR.SetValue (0, 0)' Error Tip: The object reference is not set to an object of the object MessageBox.Show (arrerr.rank) 'error message: not set to the object reference Example

DIM Arrerr2 As New Array 'Error Tip: "New" cannot be used on the classes declared "Mustinherit"

Array's GetHashCode method: Object.gethashcode method is used as a specific type of hash function, which is suitable for use in a hash algorithm and data structure (such as a hash table). (Tom Day has been studying the hash)

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

New Post(0)