vb.net - Changing the properties of an object in a HashTable -


i have hashtable called hashtable in vb.net populated stock class:

<serializable()> public class stock     'create structure hash table stock file     <vbfixedstring(10)> public barcode string     <vbfixedstring(20)> public category string     <vbfixedstring(20)> public title string     <vbfixedstring(20)> public description string     <vbfixedstring(4)> public quantity integer     <vbfixedstring(8)> public rrp double     <vbfixedstring(8)> public cost double end class 

and, when sale made edit quantity of stock. how access specific stock in hashtable change properties?

the key used identify each stock stock.barcode.

this work option strict enabled because converts object in hashtable stock data type:

dim stockitem = trycast(myhashtable(mybarcode), stock) if stockitem isnot nothing     stockitem.quantity -= quantitychange end if 

also, might want have @ dictionary(of tkey, tvalue) class. type-safe alternative hashtable. in case, you'd declare dictionary follows:

dim dict new dictionary(of string, stock)() 

you can use containskey-method check whether item available:

if dict.containskey(mybarcode)     dict(mybarcode).quantity -= quantitychange end if 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -