You can see the list i created is private and I want to be able to add objects to the list aswell as showing the user the list through methods AddBook() and ShowBooks().
public class Library
{
private List<Book> Books = new List<Book>();
public static void AddBook()
{
}
public static void ShowBooks()
{
foreach (Book item in Books)
//This foreach-loop doesn't work since its a private list.
{
Console.WriteLine("Books found");
}
}
}
The loop doesnt work since "An object reference is required for the non-static field, method, or property" refering to the list.