473,394 Members | 1,702 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,394 software developers and data experts.

extracting from an ArrayList

Hi,
In a attempt to create a dynamic multi diminsion array i am using a ArrayList object as i do not know how many dimension i will need during runtime. My code is

ArrayList mySubArray = new ArrayList();
ArrayList myArray = new ArrayList();

//while loop which can have any amount of iterations

mySubArray.Add(sName);
mySubArray.Add(sTitle);
mySubArray.Add(sAddress);

myArray.Add(mySubArray.Clone());

mySubArray.Clear();

Loop

QUESTION
how do i extract the nodes from my subArray object that is within the myArray ArrayList.

Thanks.
Jan 28 '08 #1
9 1594
r035198x
13,262 8TB
Hi,
In a attempt to create a dynamic multi diminsion array i am using a ArrayList object as i do not know how many dimension i will need during runtime. My code is

ArrayList mySubArray = new ArrayList();
ArrayList myArray = new ArrayList();

//while loop which can have any amount of iterations

mySubArray.Add(sName);
mySubArray.Add(sTitle);
mySubArray.Add(sAddress);

myArray.Add(mySubArray.Clone());

mySubArray.Clear();

Loop

QUESTION
how do i extract the nodes from my subArray object that is within the myArray ArrayList.

Thanks.
Just do myArray[i] . That will return an ArrayList. You then call list[i] on the returned ArrayList to get the "nodes".

However, that design is very bad and cumbersome. Better have a Details class that has sName, title, adddress e.t.c as properties.
You'll then need only one ArrayList of type ArrayList<Details>.
Object oriented design really makes the programming much easier.
Jan 28 '08 #2
Just do myArray[i] . That will return an ArrayList. You then call list[i] on the returned ArrayList to get the "nodes".

However, that design is very bad and cumbersome. Better have a Details class that has sName, title, adddress e.t.c as properties.
You'll then need only one ArrayList of type ArrayList<Details>.
Object oriented design really makes the programming much easier.
Is this what you mean:

public class MemberDetails
{
public string sName = null;
public string sTitle = null;
public string sAddress = null;

public MemberDetails()
{
}

public MemberDetails( string Name,
string Title,
string Address,)
{
this.sName = Name;
this.sTitle = Title;
this.sAddress = sDoc;
}
}


//loop
myArray.Add(new MemberDetails(sName, sTitle, sAddress));
//loop end

//get back nodes
foreach (MemberDetails member in myArray)
{
string memberName = member.sName;
string memberTitle = member.sTitle;
string memberAddress = member.sAddress
}

Thanks for making it clear
Jan 28 '08 #3
r035198x
13,262 8TB
Yep, you've got it.
Jan 28 '08 #4
Plater
7,872 Expert 4TB
If you are talking a large amount of data that you might want to do "work" on, you might consider using a DataTable.
Give yourself a "column" for each value you want to track, then make a new "row" for each entry.
Jan 28 '08 #5
If you are talking a large amount of data that you might want to do "work" on, you might consider using a DataTable.
Give yourself a "column" for each value you want to track, then make a new "row" for each entry.
So what are the major issues/drawbacks for using my current way if lets says i had 2000 rows to process?
Jan 28 '08 #6
Plater
7,872 Expert 4TB
I am not sure if there is much difference in "resource" usage.
Just a difference in how you access the data.

Also, I am not positive on this, but I *think* there is a way you can do SQL queries against a dataset. (Like finding everyone who's name starts with a "P" or something)
Jan 28 '08 #7
OK cool, thanks for your advice/help
Jan 28 '08 #8
r035198x
13,262 8TB
So what are the major issues/drawbacks for using my current way if lets says i had 2000 rows to process?
You'd need to be calling ArrayList.TrimToSize otherwise you'd be wasting space because arraylist's capacity is always >= arraylist's count.
The most memory efficient approach would probably be to use a struct.
However, all this depends (as Plater said) on what you want to do with the data.
Jan 28 '08 #9
I'm just passing the data into a stored procedure one by one, so I don't need to run any queries on the dataset before hand, but i think your right it would be better to use a struct instead.
Jan 28 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nazgul | last post by:
Hi! I want to implement a small tool in Python for distributing "patches" and I need Your advice. This application should be able to package all files chosen by a user into a self-extracting.exe...
2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
0
by: Mico | last post by:
I would be very grateful for any help with the following: I currently have the code below. This opens a MS Word document, and uses C#'s internal regular expressions library to find if there is a...
0
by: Bubbles | last post by:
Hello. New to ASP.NET and struggling on this one. I have a text file with a bunch of text in it. Throughout the file words followed by a ":" will appear. I need to pull every such string out...
3
by: Sonny Sablan | last post by:
AryUnderNav = New ArrayList() AryUnderNav.Add("Under $50") AryUnderNav.Add("$50 - $100") AryUnderNav.Add("$100 - $200") AryUnderNav.Add("$200 +") UnderNav.DataSource = AryUnderNav ...
0
by: k_nil | last post by:
I have a link on my web page for a self extracting executable file placed on the server. When the link is clicked, 1) i could see dialog box with open or save options 2) when open clicked, self...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
0
jawaharcsc
by: jawaharcsc | last post by:
Hi Friends,, Im new to exchange server, I want to extract the Public address list (GAL) from exchange server through .net(C# application.) and store it in arraylist to compare the mail address in...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.