Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiency: Creating an array of doubles incrementally?

Tags:

c#

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?

like image 337
Alan Avatar asked Mar 30 '10 08:03

Alan


1 Answers

There's nothing wrong with your approach. You are using the correct data type for the purpose.

like image 113
Darin Dimitrov Avatar answered Oct 20 '22 00:10

Darin Dimitrov