I just want to retrieve a particular InventoryID and with the help of InventoryID, I want to remove specific list members that match the InventoryID. For example, if the input is something like "INPOL". I want check this Id with arraylist and remove id,name,unit price and quantity that matches the input given by user("INPOL");
{
List<Inventory> inventories = new List<Inventory>();
inventories.Add(new Inventory { InventoryId = "INDHS", InventoryName = "Office Chair", InventoryUnitPrice = 51, InventoryQty = 25 });
inventories.Add(new Inventory { InventoryId = "INCDS", InventoryName = "Beds", InventoryUnitPrice = 105, InventoryQty = 12 });
inventories.Add(new Inventory { InventoryId = "INING", InventoryName = "Dinning Tables", InventoryUnitPrice = 23, InventoryQty = 10 });
inventories.Add(new Inventory { InventoryId = "INOPL", InventoryName = "Desks", InventoryUnitPrice = 155, InventoryQty = 7 });
inventories.Add(new Inventory { InventoryId = "INWSZ", InventoryName = "Book Cases", InventoryUnitPrice = 80, InventoryQty = 34 });
inventories.Add(new Inventory { InventoryId = "INQAB", InventoryName = "Coffee Tables", InventoryUnitPrice = 30, InventoryQty = 50 });
return inventories;
}
public void removeInventory(List<Inventory> inventories){
Console.Write("Enter Inventory Id: ");
InventoryId = Console.ReadLine();
foreach(Inventory inventory in inventories){
inventory.getId(InventoryId,inventories);
}
}
public void getId(string? inventoryID, List<Inventory> inventories){
if(inventoryID == InventoryId){
inventories.Clear();
}
}```