c# - Getting average values from one Array to another Array -


i’m no programmer i’m learning c# build foreign exchange trading system , arrays being struggle…

the problem have following…

i have 1 dimensional array with, let’s say, 100 elements in it.

now need build 1 dimensional array 10 elements rolling average based on first array.

said in way, need take elements first array starting in = 0 = 9 , average them , save average in new array. move 1 step forward , take = 1 = 10 original array , average them , save result in new array….and forth….in excel extremely easy….

my need have data in arrays because later need compare last 10 elements rolling average historical data….

please, can build sample code can work with?

many paulo

maybe work... did on mac in sublime text you'll still have work with. should point though.

 public class foo   {     list<int> main = new list<int>(100);     list<int> rollingaverages = new list<int>(100);      public void add(int score)     {         main.add(score);         if(main.count > 10)         {             int rollingaverage = averagelast10();             rollingaverages.add(rollingaverage);         }     }      public int averagelast10()     {         int sum = 0;         for(int = main.count - 10; < 10; i++)         {             sum += main[i];         }         return sum / 10;     }  }      somewhere else in code  foo foo = new foo(); foo.add(94); foo.add(94); ...  yadda yadda yadda 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -