locked
Using array with unkown number of items RRS feed

  • Question

  • User69570187 posted

    Hi Everyone,

    I'm trying switch from using arraylist to arrays. Seams like arrays are not as easy to use when you don't know the size of the array.

    Is it possible to use an array without having to specify the size of the array like in this example?

    Thanks in advance.

     

     dr = cmd.ExecuteReader
    
                        Dim counter As Integer = 0
                        Dim myarray() As String
                        While dr.Read()
                            myarray(counter) = dr("FirstName").ToString
                            counter += 1
                        End While
    
                        Return myarray
    Thursday, April 7, 2011 9:12 AM

Answers

  • User312496708 posted

    Why not use a list instead of array where you dont have to specify any size and keep adding and retriving stuff easily.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 9:39 AM

All replies

  • User-1618234021 posted
    Hi, normal arrays must have a size to use them. Maximum, you can always re-create a bigger array when required, and copy existing entries in it. But this will be inefficient and over head. So I would suggest to stick to collection classes like ArrayList. If you have a specific requirement to use arrays, then please share it with us.
    Thursday, April 7, 2011 9:36 AM
  • User312496708 posted

    Why not use a list instead of array where you dont have to specify any size and keep adding and retriving stuff easily.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2011 9:39 AM
  • User69570187 posted

    Thanks, I'll give the list a try.

    Saturday, April 9, 2011 12:06 AM