c# - How to assign property values based on other property value of same object list -


my structure

public struct lumcummulativedata {     public byte[] lumid { get; set; }     public float ledpwr { get; set; }     public float batchargepwr { get; set; }     public float batdischargepwr { get; set; }     public float ledpwravg { get; set; }     public float batchargepwravg { get; set; }     public float batdischargepwravg { get; set; }     public float ledpwrwh { get; set; }     public float batchargewh { get; set; }     public float batdischargewh { get; set; }     public int count { get; set; }     public string lumname { get; set; }  } 

declaring list

 public static list<lumcummulativedata> cummulativedatalist      = new list<lumcummulativedata>(); 

i assign value lumid cummulativedata.lumid = lumidbyte;(assigned id value)

now want write condition such other property values of list object(same object) must assigned based on lumid matching lumid network packet.

logic tried

for(int i=0; i<cummulativedatalist.count(); i++) {     bool lumidmatched = cummulativedatalist[i]                         .lumidcummulativedata                         .sequenceequal(packet.selfid);       if(lumidmatched == true)     {         cummulativedata.ledpwr += packet.ledpwr;         cummulativedata.batchargepwr += packet.batchrgpwr;         cummulativedata.batdischargepwr += packet.battdispwr;         cummulativedata.count++;         cummulativedatalist.add(cummulativedata);     } } 

list object increasing instead of adding field values existing object .which created while assigning lumid . want some logic iterate existing object's lumid , add other field values when lumid matched packet lumid network

you should using cummulativedatalist[i] instead of cummulativedata.

also, check whether need add function. because want change rather add new.

for (int i=0; i<cummulativedatalist.count(); i++) {     bool lumidmatched = cummulativedatalist[i]                         .lumidcummulativedata                         .sequenceequal(packet.selfid);       if (lumidmatched == true)     {         cummulativedatalist[i].ledpwr += packet.ledpwr;         cummulativedatalist[i].batchargepwr += packet.batchrgpwr;         cummulativedatalist[i].batdischargepwr += packet.battdispwr;         cummulativedatalist[i].count++;         //cummulativedatalist.add(cummulativedata);     } } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -