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

Can we add Collection object to Arraylist in c#?

If answer to this is yes then suppose,I am having Arraylist which contains collection object which contains string objects.Is there any way to retrieve these string objects.
Jan 28 '08 #1
2 1430
r035198x
13,262 8TB
If answer to this is yes then suppose,I am having Arraylist which contains collection object which contains string objects.Is there any way to retrieve these string objects.
Expand|Select|Wrap|Line Numbers
  1. ICollection strings = (ICollection)list[i];
  2.  
You then Enumerate over the collection to access the elements
Of course using generics makes the code less cumbersome.
Jan 28 '08 #2
Plater
7,872 Expert 4TB
If you are using regular ArrayLists and some kind of collection, we'll say a NameValueCollection for my example.

setup:
Expand|Select|Wrap|Line Numbers
  1. ArrayList al = new ArrayList();
  2. NameValueCollection nvc = new NameValueCollection();
  3. nvc.Add("name1", "value1");
  4. nvc.Add("name2", "value2");
  5. nvc.Add("name3", "value3");
  6.  
  7. al.Add(nvc);
  8.  
To access:
Expand|Select|Wrap|Line Numbers
  1. string valuestring=((NameValueCollection)al[0])["name1"];
  2. //valuestring is now "value1"
  3.  
Jan 28 '08 #3

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

Similar topics

4
by: m. pollack. | last post by:
Hi all, Is there any information to be had about the "Object Collection Editor" that appears when you click on a collection property in the PropertyGrid control? I have a class that maintains a...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
1
by: Dan H. | last post by:
Hello, I have an application that requires a collection that is sorted by a double field first, and then by a long field. So, lets say I have an class that has 2 fields called time, priority. I...
7
by: Gary | last post by:
I would like to make a strongly typed, sortable collection by leveraging a Framework class. I began by looking at CollectionBase but it doesn't have built-int sorting. I would prefer to derive...
7
by: juli | last post by:
I have strings variables in a collection list and I want to create new collection but to add to it only strings that are distinct (no common strings). For example I have an object sentense which...
7
by: Franck Diastein | last post by:
Hi, I'm trying to remove items from a collection this way: foreach(Object myO in ObjectCol){ if(myO != "xxx"){ myO.Remove(); } } But I'm having an error telling me that Collection was...
1
by: vbvjain | last post by:
I am developing an applocation which reads mails in outlook inbo alongwith attachments and all these informmation is stored in collection which i need to pass it to a web service, which will perfor...
1
by: Jeff Haumesser | last post by:
I have a Collection called Grooming. Each object in this collection contains the property GroomingServices of type Collection. I also have a Clone of this Groomings collection called GroomingsInit....
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
5
by: Nikolay Belyh | last post by:
I have created a "collection" in C# like this: namespace ClassLibrary1 { public class X {} public class Class1 { public ArrayList objs {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.