Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hello !
I wanna declare a string array without specifying the size of string array in vb.net. That is, as new element comes, the array should grow at run time.
How can i do that?
Thanx in advance
Posted 22-May-12 23:40pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use a List instead:
Dim myList As New List(Of String)()
myList.Add("Hello")
myList.Add("Goodbye")
Console.WriteLine(myList(1))
If you need it as an array at any time (to pass it to a method for example):
Dim myArray As String() = myList.ToArray()
  Permalink  
Comments
VJ Reddy at 23-May-12 5:13am
   
Nice answer. 5!
KNK143 at 23-May-12 5:24am
   
Hi,
Dim myList As New List(Of String)() is showing an error...Comma,')' , or a valid continuation expected...
OriginalGriff at 23-May-12 5:31am
   
I just pasted the code in my answer into a VB page and it compiles cleanly - check your code and make sure it is identical. If you can't see a problem, then copy and paste the relevant section of your code with the error message here.
losmac at 23-May-12 11:16am
   
Good answer, my 5!
005bharat at 31-May-13 4:53am
   
Great work!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

If you wont use Generics, you can do it directly:

        Dim s() As String
        ReDim Preserve s(UBound(s) + 1)
        s(UBound(s)) = "new valor"
  Permalink  
Comments
KNK143 at 12-Jun-12 5:55am
   
thanks...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Dim webQuery As QueryWebService.Service = New QueryWebService.Service
 

    Dim queryDetails As String()
    Dim i As Integer = 0
 
    queryDetails = webQuery.getStudentQuery()
 
    While i < queryDetails.Length
        txtQuery.Text = txtQuery.Text + " " + queryDetails.GetValue(i)
        i = i + 1
    End While
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Dim stringArray As String()
 
' define three strings
Dim value1 As String = "lions"
Dim value2 As String = "tigers"
Dim value3 As String = "bears"
 
' using the Split() command, dynamically create them as a three element array
stringArray = Split(value1 + "," + value2 + "," + value3)
 
' define a fourth string
Dim value4 As String = "Oh my!"
 
' dynamically add to the array
stringArray = Split(Join(stringArray, ",") + ","+ value4, ",";)
 
' or, you could ...

stringArray = Split("lions" + "," + "tigers" + "," + "bears", ",")
stringArray = Split(Join(stringArray, ",") + "," + "Oh my!", ",")
  Permalink  
Comments
CHill60 at 17-Jun-13 17:18pm
   
It's great that you want to help but this question is a year old and already resolved
Naveen_143 at 5-Jul-13 4:49am
   
thanks for your reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 144
1 Maciej Los 129
2 Sascha Lefévre 110
3 Abhinav S 104
4 Richard MacCutchan 90
0 Sergey Alexandrovich Kryukov 6,578
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Abhinav S 2,358
4 Maciej Los 2,352


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 17 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100