.net - Why isn't my item in an array getting updated? -


i have array of objects, find item index, assign value looking @ array item doesn't show updated value.

public structure cheque     public id string     public status byte     public amount string     public warrantno string end structure  public class chequecollection      private chequecoll() cheque 'this populated ok  public sub updatechequeamount(byval id string, byval amount string)         synclock lockobject             dim idx integer = get_idx(id) 'finds ok             if idx <> -1                 dim cheque cheque = chequecoll(idx)                 cheque.amount = amount 'updates value ok if in chequecoll value isn't there             end if         end synclock     end sub  end class 

because value types copied everywhere they're used - you're updating copy of value type that's in cheque variable, opposed copy within array.

you'd need update copy in array:

            dim cheque cheque = chequecoll(idx)             cheque.amount = amount 'updates value ok if in chequecoll value isn't there             chequecoll(idx) = cheque 

and of course, worth reading "the truth value types" mr. lippert


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -