I'm new to C# and have set myself a mini project of creating a To Do List type application where there's a set menu and you choose an option from the menu etc etc.
I'm having trouble with calling the methods in the main class. Here is my code:
class ToDo
{
public ToDo()
{
actions = new List<string>();
}
public static int Menu()
{
Console.WriteLine("Welcome to your To Do List!\n");
Console.WriteLine();
Console.WriteLine("\n1. View the current list?");
Console.WriteLine("\n2. Add to list?");
Console.WriteLine("\n3. Delete from the list?");
Console.WriteLine("\n4. Clear the list?");
Console.WriteLine("\n5. Exit \n");
Console.Write("\nWhat Would you like to do?: ");
var selection = Console.ReadLine();
return Convert.ToInt32(selection);
}
public void AddToList()
{
Console.WriteLine("What would you like to add to the list?");
string userInput = Console.ReadLine();
actions.Add(userInput);
}
and my main method:
class Program
{
static void Main(string[] args)
//Keep displaying menu till user chooses option 5. Exit
{
int userInput = 0;
do
{
userInput = ToDo.Menu();
} while (userInput != 5);
//If input = 2, call the Add to List method
if (userInput == 2)
{
ToDo.AddToList();
}
}
}
The problem im having is that in the main method, its not calling the "ToDo.AddToList();".
Could anyone help? Or if i'm approaching this completely wrong, any advice would be appreciated!
Thanks