Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert array to array list

Status
Not open for further replies.

davida37

IS-IT--Management
May 10, 2006
113
GB
hi,

vb.Net 2005.

I need to be able to convert an array to an array list. is this possible? If possible, an example would be great.

thanks
david
 
Dim iArray() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim ArrList As ArrayList
ArrList.AddRange(iArray)



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
ArrayList is a class, so you'll need to initialise it

ArrList = New ArrayList()

In fact, come to think of it, there's an ICollection constructor for ArrayList objects, and Arrays offer ICollection, so hows about this:

Code:
Dim iArray() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim ArrList as ArrayList = New ArrayList(iArray)

mmilan
 
Why do you need an ArrayList? You are using VB 2005, so:

Code:
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		Dim IntegerArray() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
		Dim IntegerArrayList As List(Of Integer) = IntegerArray.ToList

		'to test:
		For a As Integer = 0 To IntegerArrayList.Count - 1
			MessageBox.Show(IntegerArrayList(a).ToString)
		Next

	End Sub


Hope this helps.

[vampire][bat]
 
Ignore my previous post. [tt].ToList[/tt] was not introduced until Framework version 3.5.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top