anybody how to pass arraylist value in to another class?
pls help..
tnx
Printable View
anybody how to pass arraylist value in to another class?
pls help..
tnx
You'll have to be way more specific then that. Are you talking about the constructor or a method perhaps? With that said, it's not any different from passing any other argument type.
Also, there is usually no good reason to be using ArrayList - you should use a strongly typed List(Of T). So for example if your ArrayList contains just string values then you would have:
vb Code:
Dim MyList As New List(Of String)
yes,i only pass string value and i stored it into an arraylist..and i wanted to access this arraylist value into another form..is arraylist the right to use?
tnx
by the way i am using VB2003..i try list but i think this not supported in this version..
Ah, no its not supported in that version unfortunately. If you mark your thread as VS 2003 then people will know not to suggest things that are not available to you.
Anyway, you need to explain what exactly you are trying to do but speaking in general, to pass a value in an ArrayList to anything (a class, a method, whatever) you just do this:
That's assuming you want the first item in the list, if you wanted the second item it would be:vb Code:
MyArrayList.Item(0)
vb Code:
MyArrayList.Item(1)
If you wanted to do something for every single item in the list, you could either pass the actual ArrayList itself to your class/method and then that would do a loop or you could do a loop and call the method, like so:
vb Code:
For Each str As String In MyArrayList MyMethod(str) 'calling a method and passing the current string in the loop to it End For
Thats all a bit general but its hard to give you anything more specific when you havent given us any information..
thank you very much chris128
that would be a big help! it solved my problem..
tnx
glen
Give class2 a property of type List() and then assign your array list to that property.
Dim c2 As New Class2
c2.TheFinalList = myArrayList
thanks mendhak..