473,394 Members | 1,699 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.

adding collection to another collection...

How can i add a collection to another collection ?

For example :
---------------------------------------------
StringCollection strColl= new StringCollection(); //string series
Hashtable hshCol= new Hashtable(); // main collection for string series

strColl.Add("white"); //first series starting
strColl.Add("hot");
strColl.Add("little");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)

strColl.Clear();
strColl.Add("red"); //second series
strColl.Add("cold");
strColl.Add("big");
hshCol.Add(2, strColl);// second series has been added second collection
-------------------------------------------------

In this situation, can i get string series via the key value of hashtable
collection (hshCol) ?
I need string values of strColl from hshCol , is it possible ?
Thanks ...

Adam
Sep 8 '07 #1
4 4771
Adam Right wrote:
How can i add a collection to another collection ?
Well, one way would be to do it just as the code you posted.
For example :
---------------------------------------------
StringCollection strColl= new StringCollection(); //string series
Hashtable hshCol= new Hashtable(); // main collection for string series

strColl.Add("white"); //first series starting
strColl.Add("hot");
strColl.Add("little");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)
StringCollection is, like all objects in C#, derived from Object and can
be added to a HashTable just like any other object. So, nothing's wrong
with the above code.
[...]
In this situation, can i get string series via the key value of hashtable
collection (hshCol) ?
Yes. The same way you'd get any other object from the HashTable. For
example:

StringCollection strColl = hshCol[1] as StringCollection;
I need string values of strColl from hshCol , is it possible ?
See above. You've already posted most of the code related to
accomplishing what you seem to want, so it's not clear to me what
question you actually have. You seem to already know the answer. If
there's something specific giving you trouble, perhaps you could be more
precise about what that is.

Pete
Sep 8 '07 #2
Hashtables are depricated. Use the Dictionary and things might be a
bit more clear for you.

Sep 8 '07 #3
not_a_commie wrote:
Hashtables are depricated. Use the Dictionary and things might be a
bit more clear for you.
I don't see anything in MSDN saying that the Hashtable class is
deprecated. I also don't see how using a Dictionary<instead would
make the issue "a bit more clear". The two behave in very similar ways
and someone who is confused using one is likely to be confused using the
other.

Pete
Sep 8 '07 #4
Adam Right <n/a@n/a.comwrote:
How can i add a collection to another collection ?

For example :
---------------------------------------------
StringCollection strColl= new StringCollection(); //string series
Hashtable hshCol= new Hashtable(); // main collection for string series

strColl.Add("white"); //first series starting
strColl.Add("hot");
strColl.Add("little");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)

strColl.Clear();
strColl.Add("red"); //second series
strColl.Add("cold");
strColl.Add("big");
hshCol.Add(2, strColl);// second series has been added second collection
-------------------------------------------------

In this situation, can i get string series via the key value of hashtable
collection (hshCol) ?
I need string values of strColl from hshCol , is it possible ?
Just use:

StringCollection collection = (StringCollection) hshCol[1];

(Or whichever key you want.)

If you're just going to use sequential integer keys, however, an array
would be simpler.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 8 '07 #5

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

Similar topics

34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
10
by: David | last post by:
Can anyone give me a quick code snippet (that is standards-based) for adding OPTION tags to a SELECT dynamically. I have no problem doing it in IE but I am kind of new to the whole standards world...
4
by: Chuck Bowling | last post by:
I have a serialized TreeNodeCollection that I want to initialize a TreeView with. Is there a simple assignment I can use for this or do I have to iterate thru the collection and add individual...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
0
by: Adam J. Schaff | last post by:
Hello. I have a custom collection that implements IBindingList (allownew and allowremove are both true). I have bound it to a datagrid. I have add and remove buttons on the screen. I want to...
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
3
by: Nunzio | last post by:
I am trying to add specific form controls to a VBA collection, so that I can pass the entire collection to another function, and access the individual controls later. I have tried several...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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.