C# Equivalent of a C++ std::vector

  • Thread starter Thread starter Peter Olcott
  • Start date Start date
Peter,

In 2.0, I would use the generic List class (that's the closest
equivalent).

Before 2.0, I would use the ArrayList class (however, it is not type
safe).

Hope this helps.
 
ArrayList, or in C# 2, List<T>.

You've got to love Generics! The best new thing in .Net 2.0.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Big things are made up of
lots of little things.
 
Peter said:
What is the C# equivalent of a C++ std::vector?

Although ArrayList generally suffices as a replacement for std::vector, if
the elements are small value types there will be a loss of time and space
efficiency due to boxing and unboxing (not just the time needed for the
boxing operations, but also the impact on cache). If you're stuck with CLR
1.0, for these cases it may be more appropriate in performance-critical
sections to create your own list class based on arrays of a fixed type (or,
when dealing with single bits, to use BitArray). The generic List<> of C#
2.0 avoids this overhead. You can read more about the specific
implementation of generics in CLR 2.0 here:

http://research.microsoft.com/projects/clrgen/generics.pdf

I hope this helps.
 

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