Efficiency: Creating an array of doubles incrementally?

Posted by Alan on Stack Overflow See other posts from Stack Overflow or by Alan
Published on 2010-03-30T08:13:04Z Indexed on 2010/03/30 8:23 UTC
Read the original article Hit count: 195

Filed under:

Consider the following code:

List<double> l = new List<double>();

//add unknown number of values to the list
l.Add(0.1); //assume we don't have these values ahead of time.
l.Add(0.11);
l.Add(0.1);

l.ToArray(); //ultimately we want an array of doubles

Anything wrong with this approach? Is there a more appropriate way to build an array, without knowing the size, or elements ahead of time?

© Stack Overflow or respective owner

Related posts about c#