473,395 Members | 2,079 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,395 software developers and data experts.

Creating an ArrayList of Objects c#

Hello,

Does any one have an example of how to create an ArrayList of objects?
i.e. ArrayList of ArrayLists or an ArrayList of Hashtables?
Thanks in advance

KC

Nov 16 '05 #1
5 65327
KC,

It's like adding any other item to an ArrayList, and then retrieving
that.

For example, if you wanted to add a Hashtable to an ArrayList, then you
would do this:

// An array list.
ArrayList arrayList = new ArrayList();

// Add 100 hashtables.
for (int index = 0; index < 100; index++)
{
// Add a hashtable.
arrayList.Add(new Hashtable());
}

Now if you want to use one of the hashtables, you would have to cast the
item that the array list returns:

// Get the first hashtable.
Hashtable hashTable = (Hashtable) arrayList[0];

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Netmonster" <ne***********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hello,

Does any one have an example of how to create an ArrayList of objects?
i.e. ArrayList of ArrayLists or an ArrayList of Hashtables?
Thanks in advance

KC

Nov 16 '05 #2
What if you don't know the number of hashtables you want to add?

Nov 16 '05 #3
arraylist is dynamic

ie..

ArrayList x1 = new ArrayList();

x1.Add (your object here)
x1.Add( another object here)
etc....


"Netmonster" <ne***********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
What if you don't know the number of hashtables you want to add?

Nov 16 '05 #4
Netmonster,

The array list is self-allocating. So you just keep calling Add when
you need to in order to add a new Hashtable. You don't have to know how
many you need beforehand.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Netmonster" <ne***********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
What if you don't know the number of hashtables you want to add?

Nov 16 '05 #5
Thanks.... It is working now
KC

Nov 16 '05 #6

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

Similar topics

0
by: vande | last post by:
Hi, I am trying to create com objects in asp.net. The objects are getting created but the context in the object created is null. If I create the same object in asp the object is ok and the...
9
by: Murat Ozgur | last post by:
Hello, I want to know about "creating new objects without assignment to a reference" like this : ... new Employee("John","Woo"); .... Is this a good programming practice ? How does...
4
by: Alvo von Cossel I | last post by:
hi, i have been asked to make a good-looking app for a friend. i have an options form with a big tabstrip in it. 1. how can i customize it e.g. change from the standard system style...
1
by: Al | last post by:
Anyone know why MS says you can't create a COM class with VB.NET to use in other VB.NET projects? (reference the statement at the bottom of the MSDN article ... Walkthrough: Creating COM Objects...
4
by: Oenone | last post by:
Hi all, If I have the name in a string of one of the framework's core classes (such as "System.Collections.ArrayList"), what's the easiest way for me to create an instance of the appropriate...
8
by: Wilbur Slice | last post by:
I need to write some VB.NET objects that can be called from another environment (a Progress app, specifically). I'm having some difficulty getting this to work. My first assumption was that I...
11
by: JohnJSal | last post by:
It seems like what I want to do is something that programmers deal with everyday, but I just can't think of a way to do it. Basically, I am writing a DB front-end and I want a new "Researcher"...
3
by: cmdolcet69 | last post by:
I have a project in which i need to add to existing code. My predecessors, had all sorts of arraylist in which he would save his information. How can i create an arraylist of (intnumber) so that i...
2
by: wbosw | last post by:
I have a Arraylist (SearchSkillsArray) that contains objects. I want to place those objects into a listbox. Here i'm using get enumerator to loop through the arraylist and add the objects to the...
1
by: gvi | last post by:
Hello everybody, Here is the scenario I am calling a webservice which is returning an object type. I need to bind that to the datagrid. So I thought I would ctype the object type to arraylist...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
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...

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.