ree <re*@hotmail.co om> 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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too