ayha1999
asked on
jagged array
Hi,
what is a jagged array? pls. explain its usage with a simple and clear example.
thanks in advance
ayha
what is a jagged array? pls. explain its usage with a simple and clear example.
thanks in advance
ayha
you can do like this also
Dim vehicle(1)() as String
vehicle(0)=New String(){"Red","blue","Gre en"}
vehicle(1)=New String(){"Car","bus","truc k","bike"}
here vehicle is array size 2. First element is an array of 3 members and second element is an array of 4 members.
Dim vehicle(1)() as String
vehicle(0)=New String(){"Red","blue","Gre
vehicle(1)=New String(){"Car","bus","truc
here vehicle is array size 2. First element is an array of 3 members and second element is an array of 4 members.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Fernando,
pls. explain the follwoing:
Dim JaggedArray()() As String means we are declaring three arrays right?
need to menioned columns and row as in regluar arrays?
if I want to retrive only items from the second one (()()) how can retrieve it?
if Iwant to store only items ( from a datareader) in the third array, how can I do that?
thanks in advance.
ayha
pls. explain the follwoing:
Dim JaggedArray()() As String means we are declaring three arrays right?
need to menioned columns and row as in regluar arrays?
if I want to retrive only items from the second one (()()) how can retrieve it?
if Iwant to store only items ( from a datareader) in the third array, how can I do that?
thanks in advance.
ayha
Hi Ayha;
To your question: "Dim JaggedArray()() As String means we are declaring three arrays right?", In the sample I gave in my post there are actually 4 arrays. The first array has 3 elements in it as denoted in my table below with R0 - R2. Each one of the elements itself holds another array of different sizes also shown in the JaggedArray table Below as C0 - C3.
In the table below any location with a <> in it is not an array element. Therefore row R0 has an array of length 3, row R1 has an array of length 4, and row R2 has an array of length of 1,
JaggedArray C0 C1 C2 C3
R0 Alice Albert Allen <>
R1 Bob Bill Brenda Bert
R2 Zack <> <> <>
To your question, "if I want to retrieve only items from the second one (()()) how can retrieve it?", Let call row R1 as the second one. To access that part of the jagged array JaggedArray(R1)(Cx) therefore to access al the elements of R1 you could do it like this
For idx As Integer = 0 To JaggedArray(1).GetUpperBou nd(0)
Console.WriteLine(JaggedAr ray(1)(idx ))
Next
In this part of the For statement JaggedArray(1).GetUpperBou nd(0), JaggedArray(1) looks at row R1 and GetUpperBound(0) gets the upper bound of the only array.
To your question, "if I want to store only items ( from a datareader) in the third array, how can I do that?", As you would in a normal array.
For idx As Integer = 0 To JaggedArray(2).GetUpperBou nd(0)
JaggedArray(2)(idx) = datareader
Next
Fernando
To your question: "Dim JaggedArray()() As String means we are declaring three arrays right?", In the sample I gave in my post there are actually 4 arrays. The first array has 3 elements in it as denoted in my table below with R0 - R2. Each one of the elements itself holds another array of different sizes also shown in the JaggedArray table Below as C0 - C3.
In the table below any location with a <> in it is not an array element. Therefore row R0 has an array of length 3, row R1 has an array of length 4, and row R2 has an array of length of 1,
JaggedArray C0 C1 C2 C3
R0 Alice Albert Allen <>
R1 Bob Bill Brenda Bert
R2 Zack <> <> <>
To your question, "if I want to retrieve only items from the second one (()()) how can retrieve it?", Let call row R1 as the second one. To access that part of the jagged array JaggedArray(R1)(Cx) therefore to access al the elements of R1 you could do it like this
For idx As Integer = 0 To JaggedArray(1).GetUpperBou
Console.WriteLine(JaggedAr
Next
In this part of the For statement JaggedArray(1).GetUpperBou
To your question, "if I want to store only items ( from a datareader) in the third array, how can I do that?", As you would in a normal array.
For idx As Integer = 0 To JaggedArray(2).GetUpperBou
JaggedArray(2)(idx) = datareader
Next
Fernando
for ex
Dim ar1() As Integer = {1, 2, 3}
Dim ar2() As Integer = {4, 5}
Dim allarray()() As Integer = {ar1,ar2}