473,941 Members | 15,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding collection to another collection...

How can i add a collection to another collection ?

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

strColl.Add("wh ite"); //first series starting
strColl.Add("ho t");
strColl.Add("li ttle");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)

strColl.Clear() ;
strColl.Add("re d"); //second series
strColl.Add("co ld");
strColl.Add("bi g");
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 4859
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 :
---------------------------------------------
StringCollectio n strColl= new StringCollectio n(); //string series
Hashtable hshCol= new Hashtable(); // main collection for string series

strColl.Add("wh ite"); //first series starting
strColl.Add("ho t");
strColl.Add("li ttle");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)
StringCollectio n 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:

StringCollectio n strColl = hshCol[1] as StringCollectio n;
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<inst ead 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 :
---------------------------------------------
StringCollectio n strColl= new StringCollectio n(); //string series
Hashtable hshCol= new Hashtable(); // main collection for string series

strColl.Add("wh ite"); //first series starting
strColl.Add("ho t");
strColl.Add("li ttle");
hshCol.Add(1, strColl); //the first one adding second one(to hashtabe)

strColl.Clear() ;
strColl.Add("re d"); //second series
strColl.Add("co ld");
strColl.Add("bi g");
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:

StringCollectio n collection = (StringCollecti on) 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.co m>
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
4243
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 "push_back" a copy of this into a vector V. This is repeated many times in an iterative process. Ok whenever I "push_back" a copy of Class A, I also want to assign a pointer contained in an exisiting instance of a Class B to this
10
4904
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 and can't figure out how to make it work in, for instance, Firefox. Right now the code I am using is as follows: newOpt=document.createElement('OPTION'); newOpt.id='optKeyword'; newOpt.label='Keyword';...
4
13166
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 Nodes?
3
4903
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 the best method? Do you have a sample of how to do this?
4
2509
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 the table. I know that I can dynamically add controls (eg a textbox) to the page controls collection of a web form in a server event which will then be rendered onto the form, as in the following snippet: System.Web.UI.WebControls.TextBox...
0
3010
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 implement those buttons, but I'm not sure what the code should look like. I tried what I thought was obvious code: myCollection.AddNew() and
6
3144
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 ToolbarButtons... Does anyone know how this could be done? Looking forward to hear from you,
47
3934
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 say, C programs consist of variables to store the input and functions to manipulate them. This would make C object-oriented - how cool would that be? Are there any problems with adding the ability to have functions
3
7009
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 different syntax variations. In each case, the receiving function produces the error 'Object Required' when I try to access any property of a control in the collection. If I reference a collection item in the debugger using its ordinal position, I see...
0
10135
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11531
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11297
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4909
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3509
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.