I feel stupid for asking this but I am struggling to quite understand foreach. Say for example that I am making a book repository app, with a Book class as well as an Inventory class. The Inventory class has a removeBook method that removes a book from the inventory. The parameter for the method would be an int bookID. I am thinking I should use foreach to accomplish this. I understand the most basic use of foreach but I can not figure out how to use it to basically select a specific bookID that is a parameter in the method. Could someone help point me in the right direction?
Here's a code snippet, I know the method is wrong:
List<Book> Books = new List<Book>
{
new Book{ bookID = 5, Name = "Moby Dick", Price = 20.00 },
new Book{ bookID = 2, Name = "50 Shades of Grey", Price = 0.99 }
};
public void removeBook(int bookID)
{
foreach (var bookID in Books)
{
Products.Remove(book);
}
}