I have this object list named list<product> A within class USER, there is also a list<USER> in the main program we name list C.
List A will be updated every time the user buya something from another list<product> B (this on is on the main class) that contains every product we have and some additional information on how much it costs (based on user age) and when it was bought (which variable exist from the product class, although it's empty when it's inside list A as I only want to save the product name, and product description in list B).
If the product the user bought does not exist in list B then it will print "no product exists". If it exist it will add the product the user bought to List A. The program does not run as intended, the add to list A is running fine (although it somehow updates the list B product with the same name?), if the user buys a different product but if it's the same product the list A will update every list in list product???
Here is the add product code:
public static Produk Sehat = new Produk("Sehat Bersama",EnumJenisKesehatan.Kesehatan
,EnumFrequensi.Bulanan,"Claim Perawatan kelas 1");
public static Produk SehatExtr = new Produk("Sehat Extra", EnumJenisKesehatan.Kesehatan
, EnumFrequensi.Bulanan, "Claim Perawatan VIP");
public static List<Produk> allprod = new List<Produk>()
{ Sehat,SehatExtr};
Here is the add product to list (with the assumption that we've got the product we want to add, and the user that bought it).
Tempuser._produk.Add(produk);
Here is the one that adds the price in user class to the product list (again with the asumption that we've already got the product from the user list[product]).
int price;
if (User._age < 20)
{
price= 200000m;
product._price= price;
}
else
{
price=300000m;
product._price=price;
}
I even made the product list into a dictionary (with product as value and and ID as the key) but the code still updates every product with the same name and my senior tends to get mad at me, if I ask her this kind of question....
Please someone is there some kind of solution to this?