The following three examples of vb.net Array Operations mainly refer to the data elements, data length, and data change values. The code of the three instances is as follows:
Increase Data Length
Imports system
Public class mainclass
Shared sub main ()
'Clare an array
Dim strfriends (4) as string
'Populate the array
Strfriends (0) = "r"
Strfriends (1) = "B"
Strfriends (2) = "s"
Strfriends (3) = "s"
Strfriends (4) = "k"
Redim preserve strfriends (6)
Strfriends (5) = "m"
Strfriends (6) = "j"
For each strname as string in strfriends
System. console. writeline (strname)
Next
End sub
End class
Specify a value for the data element again
Imports system
Public class mainclass
Shared sub main (byval args as string ())
Dim friends () as string = {"a", "B", "c", "d", "e "}
'Make friends bigger!
Redim friends (6)
Friends (5) = "f"
Friends (6) = "g"
Addfriendstolist (friends)
End sub
Shared sub addfriendstolist (byval friends () as string)
Dim friendname as string
For each friendname in friends
Console. writeline ("[" & friendname & "]")
Next
End sub
End class
Change Data Length
Imports system
Public class samplesarray
Public shared sub main ()
Dim myarr as string () = {"the", "quick", "brown", "fox", "jumps tutorial", "over", "", "lazy", "dog "}
Printindexandvalues (myarr)
Array. resize (myarr, myarr. length + 5)
Printindexandvalues (myarr)
Array. resize (myarr, 4)
Printindexandvalues (myarr)
End sub 'main
Public shared sub printindexandvalues (myarr () as string)
Dim I as integer
For I = 0 to myarr. length-1
Console. writeline ("[{0}]: {1}", I, myarr (I ))
Next I
End sub
End class