Creating Collections in C#

  • Thread starter Thread starter john sutor
  • Start date Start date
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
 
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.
 
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]
 
Back
Top