I'm kinda new to c#, attempting to make a Phonebook Console App. Need some help figuring out how to call the list from another class. To understand my code: I've got a class (ContactsList) which contains the list. Then I've got another class (AppOptions) which has a few options the user can select, one being ViewAllContacts. So I need to know what code I need to write in the ViewAllContacts method, and if any other changes need to be made anywhere else.
public class ContactsList
{
public string contactName { get; set; }
public int contactNumber { get; set; }
public void listMethod()
{
List<ContactsList> contacts = new List<ContactsList>();
{
contacts.Add(new ContactsList { contactName = "John", contactNumber = 01 });
contacts.Add(new ContactsList { contactName = "Jack", contactNumber = 02 });
contacts.Add(new ContactsList { contactName = "Jay", contactNumber = 03 });
}
}
}
class AppOptions
{
ContactsList contactList = new ContactsList();
public void viewAllContacts()
{
}
}
Any extra improvement for my code would be really appreciated. Thanks!
EDIT: Another important thing I wanted was to loop through the list using the ViewAllContacts method