By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,664 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,664 IT Pros & Developers. It's quick & easy.

Creating Collections in C#

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Use System.Collections.ArrayList.

Chris

"john sutor" <jo********@cinfin.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
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

Nov 13 '05 #2

P: n/a
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.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"john sutor" <jo********@cinfin.com> wrote in message
news:O8**************@TK2MSFTNGP10.phx.gbl...
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

Nov 13 '05 #3

P: n/a
john sutor wrote:
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]
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.