Arrays

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

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top