c# - How to properly add new items to a collection? -


here trying store loads of datapoints of custom winddatapoint type.

however, found out whole time, code has been creating tens of thousands of duplicate data points. data points change latest value, yes, instead of adding new datapoint, sets datapoints value well.

here code of concern:

    private void timer_data_tick(object sender)     {         if (!timer_data_enabled)             return;         (int = 0; (itsdaq.getstreamcount() > 0) && (i < 6); i++)         {             winddaq.winddatapoint thisdatapoint = new      winddaq.winddatapoint();             thisdatapoint = itsdaq.getvalue(recording);             datapointcollection.add(thisdatapoint);             newchartpoint = true;         }      } 

here code getvalue() , getvalue(bool record)

    //get real-world values     public winddatapoint getvalue()     {         holddequeuevalue = daqstream.dequeue();         holdwinddatapoint.lift = lift_sensor.getforce(holddequeuevalue[channeloutorder[0]]);         holdwinddatapoint.drag = drag_sensor.getforce(holddequeuevalue[channeloutorder[1]]);         holdwinddatapoint.velocity = pitot_sensor.getvelocity(holddequeuevalue[channeloutorder[2]]);         holdwinddatapoint.isrecorded = false;          //this translates number of samples since start actual time since start         //why not current time? don't want current time. want time sample taken.         holdwinddatapoint.time = samplestotime(samplesreadsincestart);          samplesreadsincestart++;         return holdwinddatapoint;     }      //get read-world values , set whether sample recorded.     public winddatapoint getvalue(bool record)     {         getvalue();         holdwinddatapoint.isrecorded = record;         return holdwinddatapoint;     } 

  1. you shouldn't instantiating thisdatapoint if you're going redefine after.
  2. getvalue returning reference same object every time. means see same data.

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -