# Place a series of doubles into an array

• March 14th, 2011, 06:52 PM
L.C.
Place a series of doubles into an array
Forgive me if this is a newbie question but I've spent several hours working on trying to figure out alternatives to this before I came here....I'm having some trouble in figuring out what's the best way to achieve what I'm trying to. I'd like to place a series of double values into an array without setting each value like this

double spread = CSCO.Bar.Close / DELL.Bar.Close;

{
double[] dataArray = new double[6];

Array.Reverse(dataArray);
}

So in other words I'd like to to cycle though all values of spread_series.Ago(0-infinity) and place them into dataArray[i] something like this.

{
for (int i = 0; i < dataArray.Length; i++)
{
Array.Reverse(dataArray);
}

}

The problem obviously is that I can't implicitly convert a double into an array and the .Ago method requires an (int) in it's reference. I've tried casting but I think the underlying framework prevents it. So I'm left wondering if it's possible to make a simple class or some other method that would allow me to reference all values in the spread_series.Ago() method programmatically so that I wouldn't have to set each value individually or if I don't know how much data I'll be referencing?

Any help is greatly appreciated!
Thank You
• March 14th, 2011, 10:04 PM
ThermoSight
Re: Place a series of doubles into an array
Hi LC.

Although you've gone to great effort to explain it, I'm still having difficulty understanding the problem, but I can't help but wonder if it's simply that you want to create an array of doubles programmatically thus relieving you of the burdensome task of entering each double explicitly.

Perhaps it's as easy as usin' a list<double> as temporary programmatic storage for doubles from your source(s) - No array needed. Then convert the list<double> to a double[] when you've gathered all the doubles you wish.

perhaps sumthin' sorta like the following ? ....
Code:

``` using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; using extensions; namespace logParser {     public partial class sumthin {         // ***********************************************         // Create a huge source of doubles to         // model his "spread_series" (whatever that is)         // ***********************************************         static double[] humongous = new double[1492];         static public double[] hugeArray {get {return humongous;}}     }     public partial class Form1 : Form     {         // *****************************************************         // call the function, providing the source of doubles 'spread_series'         // *****************************************************         private void testProgrammaticArrayCreation(){             programmaticallyCreateDoubleArray(sumthin.hugeArray);         }         // ***********************************************************************         // here's the function that allows one  to programmatically gather doubles from the source,         // then converts them to a double[] for easy handling.         // ***********************************************************************         public double[] programmaticallyCreateDoubleArray(double[] spread_series) {             List<double> aggregate = new List<double>();             double[] result = new double[0];             // **************************************************************************             // He doesn't tell us what "Ago" is so I feel free to make it whatever I wish             // which is a double extension function that returns 'i' as a double             // (See namespace 'extensions', function "Ago" below).             // **************************************************************************             if (spread_series.Length > 7) {                 for (int i = 0; i < spread_series.Length; i++) {                     aggregate.Add((spread_series.Ago(i))[0]);                 }                 result = aggregate.ToArray();             }             return result;         }// end function 'programmaticallyCreateDoubleArray'         // ***********************************************************************     }// end class }// end namespace namespace extensions {     public static class ext {         public static double[] Ago(this double[] a, int  i) {             return new double[] { (double)i } ;         }     } }```