Hi all,
ArrayList is a generic structure.
Let's say I have my own structure (contained of Boolean+string+int). I want to set a dynamic array based on my own structure. How....?
Thanks!
Printable View
Hi all,
ArrayList is a generic structure.
Let's say I have my own structure (contained of Boolean+string+int). I want to set a dynamic array based on my own structure. How....?
Thanks!
This is a example about dynamic arrray :
If you want to keep the existing items in the Array , you can use the keyword Preserve .Code:Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim scores() As Integer
ReDim scores(1)
scores(0) = 100
scores(1) = 200
For i = 0 To scores.Length - 1
MsgBox(scores(i))
Next
ReDim Preserve scores(2)
scores(2) = 300
For i = 0 To scores.Length - 1
MsgBox(scores(i))
Next
End Sub
End Class
ReDim Preserve scores(2) :
In this case the Array dynamically allocate one more String value and keep the existing values.
When you say "generic" don't mean it in the .NET sense, because an ArrayList is not a generic class, which is the problem. From .NET 2.0 onwards you should not use an ArrayList at all but rather use the List(Of T), which is a generic class. If you have your own type named SomeType, you would create a List(Of SomeType). The collection will then only accept SomeType objects and it will return its items as SomeType values rather than Object references.
Thanks. That's what I meant.
Can you write the releavnt syntax?
You dont need to do all that though, as JMC has explained you can just use the generic List(Of T) like so:
vb Code:
Dim MyCustomTypeList As New List(Of MyCustomStructure) Dim structureinstance As New MyCustomStructure structureinstance.SomeStringProperty = "a string" 'etc etc MyCustomTypeList.Add(structureinstance)
Get the idea?
EDIT: When you say "its a VB6"... do you mean your application is written in VB6? If so, you should post it in the VB6 forum and not the VB.NET forum
VB6 wouldn't have the ArrayList, so the interpretation of Redim being VB6 is that it is legacy.
Ah, thats what I was hoping :) thanks for the clarification
That's exactly what I meant :-)
Thanks you all!
Dont forget to mark your thread as Resolved if you've got everything you need (go to the Thread Tools menu at the top of your first post in this thread)