I created a list based on struct but can't change item value. so I used a class instead of struct but the problem when I printed the list it's give me the latest item inserted duplicate as per the number of items.
eg. if I insert "A" , "B" , "C" then output will be C C C not A B C
Here is the code :
public struct Item //this is working fine but can't change item price
{
public string Code { get; set; }
public string Description{ get; set; }
public string Price{ get; set; }
public string Qty { get; set; }
}
public static Class Item //this is not working it's overwrite the last value
{
public string Code { get; set; }
public string Description{ get; set; }
public string Price{ get; set; }
public string Qty { get; set; }
}
Rest of code
public static Item xItem = new Item();
public static List<Item> item = new List<Item>();
xItem.Code = txtCode.Text;
xItem.Description = txtDescription.text;
xItem.Price= txtPrice.text;
xItem.Qty = txtQty.text;
I tried both of this (gives same result)
item.Insert(i,xItem);
// and
item.Add(xItem);
in btnSave_Click
I add this
foreach (var s in item)
{
System.Diagnostics.Debug.WriteLine(s.Code +" \t " + s.Qty);
}