473,503 Members | 2,152 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Collections in C#

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
3 13728
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1402
by: SS | last post by:
Hi All, I am trying to create a simple DBException Class which I want to use in different apps. Here is what I am doing: 1. I Created a VB Class Imports...
4
2031
by: Oenone | last post by:
Hi all, If I have the name in a string of one of the framework's core classes (such as "System.Collections.ArrayList"), what's the easiest way for me to create an instance of the appropriate...
5
8547
by: Mark Rae | last post by:
Hi, In v1.x, I used to use the following code to create a case-insensitive Hashtable: Hashtable MyHashtable = new Hashtable(CaseInsensitiveHashCodeProvider.Default,...
6
5139
by: MikeSwann | last post by:
Dear All, I am trying to decide on to create a collection object for a project that I am working on. I am fairly new to OOP so this may be on the basic side. I have looked on the groups, but...
7
5483
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int,...
12
3377
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
26
5335
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
5
2450
by: paulb | last post by:
Hey, Does anyone know how to create and name collections dynamically? I am writing some vb.net (VB2005) code which requires me to create an unknown number of collections and then add them to a...
8
2202
by: julia_beresford | last post by:
Hi I need to create the following class at runtime: public class MyCollection : CollectionBase { public void Add(MyItem item) { List.Add(item); }
8
2521
by: Andrus | last post by:
Code below causes error in class definition line .....Isolator<T>' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Myapp.Isolator<T>.GetEnumerator()'...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.