Arraylist

  • Thread starter Thread starter Steven
  • Start date Start date
S

Steven

I have 2 arraylists (name and value). Is there anyway that I can make that
into one arraylist with 2 columns. First column as name and second column as
value?

-- Steven
 
You are talking about a DictionaryEntry item. You will have to iterate
through your arrays and create a separate array of DictionaryEntry objects.
Or you can just add them to a a dictionary or hashtable collection.
 
Steven,

Why not use a Dictionary? Or, use a dataset, and place the values in
there (assuming that each arraylist contains the same type).

Hope this helps.
 
Hi Steven,

Arraylists are one-dimensional only.
If you want it to be multidimensional you need to create an object
(class/struct) that holds the information you want.

You could possibly transfer your arraylists via two one-dimensional arrays
into a two dimensional-array using ArrayList.ToArray and Array.Copy, but
you won't end up with an ArrayList and the time spent on doing this
transformation would probably not be worth it as iterations will do the
same in about the same amount of time.
 
My ultimate goal is to display the values in final Arraylist or Dictionary
item on my aspx page using datalist control. I dont know exactly on how to
iterate through the arrays and create a dictionary? How can I do that ?
Could you please explain a bit elaborately?

Thanks for the replies
Steven

Nicholas Paldino said:
Steven,

Why not use a Dictionary? Or, use a dataset, and place the values in
there (assuming that each arraylist contains the same type).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steven said:
I have 2 arraylists (name and value). Is there anyway that I can make that
into one arraylist with 2 columns. First column as name and second column
as value?

-- Steven
 
Steven said:
My ultimate goal is to display the values in final Arraylist or Dictionary
item on my aspx page using datalist control. I dont know exactly on how to
iterate through the arrays and create a dictionary? How can I do that ?
Could you please explain a bit elaborately?

[you can just do this:


you can create a HashTable, or you can inherit your own dictionary from
DicitonaryBase.
for(int i =0; i< Count ; i++)
{
//get each value in the ArrayList and insert it into the dictionary.

}

you can also use a enumerator to loop through.
]
Thanks for the replies
Steven

Steven,

Why not use a Dictionary? Or, use a dataset, and place the values in
there (assuming that each arraylist contains the same type).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have 2 arraylists (name and value). Is there anyway that I can make that
into one arraylist with 2 columns. First column as name and second column
as value?

-- Steven
 
Steven

You can create a class with two properties and set the instanced objects
from that in your arraylist.

I hope this helps,

Cor
 
Try the "NameValueCollection" in the System.Collections.Specialized
namespace.

Hope this helps,
Joe
 
Back
Top