Vb.net array (length, value assignment)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.