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

Handling Group of similar objects in C# ?

P: n/a
ree
I am new to C#

in C++ you can use vectors to handle a unknown quantity of set of objects.

But in C# not sure what to use.

As I tried arraylists but they can hold a variety of objects. So when I try
to use functions that go through (eg. for loop) of group objects (eg. Cars)
and get their (attributes eg. for Class Car attribute Year of Make ) I am
having compilation errors.

Is their anything easier than arraylists for C# like vectors in C++. Is
there a similar equivalent to vectors in C#?

Or should I use create an enormous array even though it will have memory
issues?
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ree <re*@hotmail.coom> wrote:
I am new to C#

in C++ you can use vectors to handle a unknown quantity of set of objects.

But in C# not sure what to use.

As I tried arraylists but they can hold a variety of objects. So when I try
to use functions that go through (eg. for loop) of group objects (eg. Cars)
and get their (attributes eg. for Class Car attribute Year of Make ) I am
having compilation errors.

Is their anything easier than arraylists for C# like vectors in C++. Is
there a similar equivalent to vectors in C#?

Or should I use create an enormous array even though it will have memory
issues?


In the future, there'll be generics. Currently, you have three options
(that I can think of off the top of my head):

1) Expose an ArrayList and document that only the relevant types of
objects should be added.

2) Don't expose the ArrayList itself - make a strongly-typed public
interface and make sure that you only put the right things in the list.

3) Derive from CollectionBase to create a strongly typed list. There
are tools around to automate this, although I haven't used them.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

P: n/a
ree... this may help:
http://www.geocities.com/jeff_louie/OOP/oop7.htm
Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.