"ZeroVisio" wrote...
Hi,
Is it possible to create two -dimensional array using ArrayList in C#? I
know you can do one-dimensional array but i dont know how to do
two-dimensional. in my case my number of columns remain same, but # of
rows
are variable. Right now I'm using DataTable for this but my feeling is it
is
not very efficient and may cause some problems.
if you have done something like this before could you please tell me how
to
do this or if using DataTable is an efficient way?
Of course you can use ArrayLists in that way, e.g.
================================
ArrayList rows = new ArrayList();
// Iterate for each new row...
ArrayList singlerow = new ArrayList();
// Iterate for each "column"...
singlerow.Add(yourItem);
// when your row is finished...
rows.Add(singlerow);
// When you want to retrieve the data...
object o = ((ArrayList)rows[0])[0];
======================================
You can also use an ordinary array as the single row, and put that into an
ArrayList:
ArrayList rows = new ArrayList();
// Iterate for each new row...
object[] singlerow = new object[4];
// Iterate for each "column"...
singlerow[0] = yourItem;
// when your row is finished...
rows.Add(singlerow);
// When you want to retrieve the data...
object o = ((object[])rows[0])[0];
======================================
In these examples I used object as the datatype, but of course you can use
the type of the actual data here...
If you use one of those, or your DataTable solution, or another
construction, really depends on how you will use the data in the end.
// Bjorn A