Array class like ArrayList is a great class because we no need to define the size of array and it will automatic adjust, but how about if I want to use 2D array? can I still use class like ArrayList? how to do?
I would try creating a class and use the two indexes as parameters in a default Item property.
ie:
public class WidgetArray
private myWidgets(iCol*iRow) as widget
inherits ArrayList 'override the methods you wish to use
public default property Items (Byval x as Integer, ByVal y as Integer) as Widget
get
return mywidgets(x,y)
end get
set (byval value as widget)
mywidgets(x,y) = value
end set
Dim alMain As ArrayList = New ArrayList
Dim iMain() As Integer = {1, 2, 3, 4, 5}
alMain.Add(iMain)
If you needed ArrayList-like functionability for the 2nd-dimension change the array into an ArrayList and add that instead. I would not recommend this method for large lists or processor intensive code blocks, nor is this a viable solution for all cases.
just Dim it once... and then make new objects like so...
Dim myThing as Object
Dim myArray as ArrayList
mything = new object(parameters)
myArray.Add(mything)
mything = new object(paramenters)
(in reality you'd probably use a Sub and use the parameters from that Sub to instantiate your new object, that way you'd only have one statement..... 'x = new x(a,b,c setting abc when you call the sub)
(obviously this is just a sample, so your needs will vary, but it's a shot)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.