c# - Error in generate code and Update list -


i try make generate 16 bit code , when add record number same how can fix ?

in loop befor code[i] = newcode; code corect when code added in list changed last code new code same last generate !!!!

public actionresult gen5rm(generatecodemodel model){          code newcode = new code();          int x = convert.toint32(model.quntity);          code[] code = new code[x];          (int = 0; < x; i++)         {                       string strdate = "";                 string strmonth = "";                 string strday = "";                 string myday = "";                  strmonth = datetime.now.tostring("mm");                 myday = datetime.now.dayofweek.tostring();                   if (myday == "sunday")                 {                     strday = "su";                 }                 if (myday == "monday")                 {                     strday = "mo";                 }                 if (myday == "tuesday")                 {                     strday = "tu";                 }                 if (myday == "wednesday")                 {                     strday = "we";                 }                 if (myday == "thursday")                 {                     strday = "tu";                 }                 if (myday == "friday")                 {                     strday = "fr";                 }                 if (myday == "saturday")                 {                     strday = "st";                 }                 strdate = generatebarcode();                 newcode.codebase = model.agent + strmonth +             model.type_code + strdate + strday + "5" + model.dealercode;                 newcode.price = 5;                 newcode.serial = "s" + datetime.now.tostring("mmssfff");                  code[i] = newcode;          }          return partialview("_return5rm", code);         } 

the export this

newcode should inside loop, otherwise items in array point same object (same memory address)

for (int = 0; < x; i++) {      code newcode = new code();     ... } 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -