473,657 Members | 2,371 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 13731
Use System.Collecti ons.ArrayList.

Chris

"john sutor" <jo********@cin fin.com> wrote in message
news:O8******** ******@TK2MSFTN GP10.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************* *@exisconsultin g.com

"john sutor" <jo********@cin fin.com> wrote in message
news:O8******** ******@TK2MSFTN GP10.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
1417
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 Microsoft.ApplicationBlocks.ExceptionManagement
4
2035
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 class? In VB6 I would have simply used CreateObject, is there an equally simple way in VB.NET? Thanks,
5
8553
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, CaseInsensitiveComparer.Default); In v2, this generates the following warnings:
6
5147
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 can't seem to find the answer I am looking for - just more questions! I want an object to hold Case details, one of the properties of this Case class will be RequestedBy. I ideally want this property to be a collection of User Objects (which...
7
5502
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, would return the value of obj because it returns the index of the item at position obj. Thoughts I had were to let the default method perform the default behavior and then create an overload as IndexOf(int index, ProductSearchCriteria criteria)...
12
3400
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. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
26
5354
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 because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
5
2455
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 master collection so I can operate on them in a loop. Thanks,
8
2212
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
2531
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()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'. I tried to change method signature to
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
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 we have to send another system
2
1959
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.