Generics

  • Thread starter Thread starter orsula
  • Start date Start date
O

orsula

Hi,

I'm looking for a generic container that can be dynamically added with
elements and maintain their order. When looping with for/foreach on
this container the elements should appear in the order of the
additions. Can you please tell me which container should I look into?

Thanks
 
The generic List<...> maintains order. Iterating with either 'for' or
'foreach' will yield the insertion ordering. Note that the generic List also
has an Insert method - this would only make sense if an ordering existed.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
 
orsula said:
Hi,

I'm looking for a generic container that can be dynamically added with
elements and maintain their order. When looping with for/foreach on
this container the elements should appear in the order of the
additions. Can you please tell me which container should I look into?

In general, almost anything that implements IList<T> should do that,
since it's an interface for positional access. To name a few actual
types - List<T>, LinkedList<T>, Collection<T>. Of all these, List<T>
is a typical default choice for the lack of any specific performance
or size requirements.
 
In general, almost anything that implements IList<T> should do that,
since it's an interface for positional access. To name a few actual
types - List<T>, LinkedList<T>, Collection<T>. Of all these, List<T>
is a typical default choice for the lack of any specific performance
or size requirements.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top