C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-06-2005, 03:31 PM   #1
Registered User
 
Join Date: May 2005
Posts: 4
"Collection" of objects in C#

Hi there,

I am trying to convert a program from VB6 into C#.NET. The VB6 code uses a very usful thing called a "collection" where you can simply add an object to it without defining the collection type. It may be a really obvious answer, but is there a similar system in C#. I looked at ArrayList but the problem with that is I can't do myArray[x].objectMethod();" for example. I want to add the object of same type to an array but at the same time, be able to reference the attributes and methods of the objects directly.

Any ideas?

Thanks,

Rich
richard_hooper is offline   Reply With Quote
Old 05-06-2005, 06:02 PM   #2
Registered User
 
The Dog's Avatar
 
Join Date: May 2002
Location: Cape Town
Posts: 777
My guess is that the C# ArrayList indexer method returns an object. This then has to be casted to your particular type, then the method can be called.
The Dog is offline   Reply With Quote
Old 05-07-2005, 08:52 PM   #3
Banned
 
nickname_changed's Avatar
 
Join Date: Feb 2003
Location: Australia
Posts: 986
The Dog is correct.

You can create strongly typed collections (which just inherit from CollectionBase and and do all the casting). There are a number of collection generators out there. A google search will show you how.

In C# 2.0 (released later this year) you can use generics to accomplish this.
Code:
Collection<WhateverTypeYouWant> myCollection = new Collection<WhateverTypeYouWant>();
nickname_changed is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
most efficient way to write filestream objects? darsunt C++ Programming 3 01-26-2009 05:17 PM
I believe I've found an official Answer to my Problem (Object Factories) Shamino Game Programming 60 12-20-2005 11:36 PM
Question about cout an stack object? joenching C++ Programming 8 05-08-2005 10:10 PM
chain of objects within pop framework help needed Davey C++ Programming 0 04-15-2004 10:01 AM
array of objects? *~*~*~* C++ Programming 4 05-31-2003 05:57 PM


All times are GMT -6. The time now is 12:04 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22