Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
Posted

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

 

 

'override add, remove and whatever else you need

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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.

Posted

there is almost never a need to do that

 

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)

 

always tryin to help

i'm not lazy i'm just resting before i get tired.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...