473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

creating two-dimensional array...

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?
Nov 17 '05 #1
3 30632
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?

How about this one.
int dimension=4;
// Place Testing Code Here
int[][] jaggedTwo = new int[dimension][];

for(int i=0; i<dimension; i++)
{
jaggedTwo [i] = new int[] {1, 2, 3};
}
John
Nov 17 '05 #2

"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
Nov 17 '05 #3
Bjorn,

That was really helpful and it works in my situation.

Thanks a lot!

"Bjorn Abelli" wrote:

"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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
3
by: Bruno Luis | last post by:
Hello I'm using A97 and i'm having some trouble with creating a recordset with data from two different databases. I connect to a remote database and make this data the default source for my...
2
by: Andrea | last post by:
I'm having some difficulty creating a report in Access and I need some suggestions. My company issues "Return Authorizations" when customers need to return products. A customer calls in and we...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
4
by: Cal | last post by:
The Help examples for creating a Registry subkey uses double backslashes between subkeys. The examples for creating a folder use a single backslash. First: Am I right in that double...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
2
by: ChrisO | last post by:
I've been pretty infatuated with JSON for some time now since "discovering" it a while back. (It's been there all along in JavaScript, but it was just never "noticed" or used by most until...
3
by: teephish | last post by:
Hello, I'm currently in the process of creating a small access database and I'm having some problems with creating a customized search. I would like the user to be able to search a record by last...
17
by: John Salerno | last post by:
Let me see if this question even makes sense...I'm reading Core Python Programming and I jumped ahead to the more specific topics like network programming. I plan to follow along with the example...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.