Creating Collections in C#

J

john sutor

How can you create a collection of objects in C# like you can in VB?
In VB you say
Dim myCol as new Collection
and then add the item and index
 
N

Nicholas Paldino [.NET/C# MVP]

John,

There is nothing that offers the EXACT functionality of the collection
class in VB (the Collection class uses string keys only, etc, etc). What
you can use in its place though is the Hashtable. This will allow you to
store items in it using any object as a key (including strings).

Hope this helps.
 
R

Reginald Blue

john said:
How can you create a collection of objects in C# like you can in VB?
In VB you say
Dim myCol as new Collection
and then add the item and index

There's one other view of Collections in .Net and VB and that is the support
of the 'for each' syntax.

In the case of .Net, a class that wants to support for_each must implement
the IEnumerable interface and, thus, support the GetEnumerator method.

Otherwise, as far as adding items and indexing items, you can do it pretty
much however you like (and there were several suggestions already which I
won't repeat).

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top