Multidimensional ArrayList how to?

  • Thread starter Thread starter SpotNet
  • Start date Start date
S

SpotNet

Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated from
an OleDbDataReader. Reason I'm using an ArrayList is I do not know the size
of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3

Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could talk
'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Many thanks and kind regards,
SpotNet
 
SpotNet said:
Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated
from
an OleDbDataReader. Reason I'm using an ArrayList is I do not know the
size
of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3

Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could
talk
'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Out of curiosity, are you populating the ArrayList[] members? All you are
showing here is the creation of the array. ALl of its members will be null
until you explicitly instantiate them.
 
SpotNet said:
Hi NewsGroup;

Trying to construct a Multidimensional (2D more specifically) populated from
an OleDbDataReader. Reason I'm using an ArrayList is I do not know the size
of the first dimension (being rows), here's my final attempt below;

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3]; //Let's just say 10, 3
MD: Here you are just initializing arry not array members. It defines the
array parameters. it will not initialize each member ArrayList objects. So
due to Null, it will throw that exception.
You have to initialize each ArrayList members explicitly.
My Suggestion: Use another Collections member, to store ArrayList objects.
May be you can use ArrayList of ArrayList objects, may be it will be more
convenient. But it depends on your program logic.
Keeping it brief and simple excuse the syntax,

GetDataMatrix[0,0].Add(15);

Throws an exception right at me stating that, 'Object reference is not an
instance of the object'. If only 'System.Collections.ArrayList' could talk
'cause I have a few hard words for it, well the multi-dimensional case
anyway. What am I doing wrong?

Many thanks and kind regards,
SpotNet

HTH,
Mahesh Devjibhai Dhola
"Empower yourself...."
 
Thanks Daniel, I'm trying to populate the array

GetDataMatrix[0,0].Add(15); throws the exception, I've got the impression
that GetDataMatrix[0,0].Add(15) method, adds the int 15 (as an object) to
the array. Inferring form your response from the declaration,

System.Collections.ArrayList[,] GetDataMatrix = New
System.Collections.ArrayList[10, 3];

I have to instantiate;
GetDataMatrix[0,0], GetDataMatrix[1,0], ...,GetDataMatrix[9,2] (in a loop of
course) and then assign them values?

Thanks again Daniel you've got me closer, I'll try it out...

Regards,
SpotNet


message :
: : > Hi NewsGroup;
: >
: > Trying to construct a Multidimensional (2D more specifically) populated
: > from
: > an OleDbDataReader. Reason I'm using an ArrayList is I do not know the
: > size
: > of the first dimension (being rows), here's my final attempt below;
: >
: > System.Collections.ArrayList[,] GetDataMatrix = New
: > System.Collections.ArrayList[10, 3]; //Let's just say 10, 3
: >
: > Keeping it brief and simple excuse the syntax,
: >
: > GetDataMatrix[0,0].Add(15);
: >
: > Throws an exception right at me stating that, 'Object reference is not
an
: > instance of the object'. If only 'System.Collections.ArrayList' could
: > talk
: > 'cause I have a few hard words for it, well the multi-dimensional case
: > anyway. What am I doing wrong?
: >
:
: Out of curiosity, are you populating the ArrayList[] members? All you are
: showing here is the creation of the array. ALl of its members will be null
: until you explicitly instantiate them.
: >
:
:
 

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

Back
Top