Arrays

  • Thread starter Thread starter et
  • Start date Start date
E

et

It seems that Arrays is one of those things that got more difficult with
..net. How can you add an item to an array? The examples I found say you
have to declare the array at the same time you set its values, which doesn't
help.

I have a public array declared in the declarations section of the module:

Dim arrKeyFields(,,) as String
Note that you cannot do "New" String

Then in a procedure, I tried to
"arrKeyFields.Add" and it tells me Add is not a member of System.Array.

So how do I add values to the array?
 
et said:
It seems that Arrays is one of those things that got more difficult with
..net. How can you add an item to an array? The examples I found say you
have to declare the array at the same time you set its values, which doesn't
help.

I have a public array declared in the declarations section of the module:

Dim arrKeyFields(,,) as String
Note that you cannot do "New" String

Then in a procedure, I tried to
"arrKeyFields.Add" and it tells me Add is not a member of System.Array.

So how do I add values to the array?

Arrays in VB.NET are of fixed size similar to C style arrays. So you can
declare and use an array of string in very simple way :

<CODE>
' Decalre an array variable
Dim strArr(3) As String

' Assign some value
strArr(0) = "test"

' Use the value from array element
Console.WriteLine(strArr(0))

</CODE>

In case you are not sure about the size of array, you may use ArrayList
which can grow dynamically.

Hope it will help.
 
Back
Top