lundi 5 avril 2021

c# need help combining if statement with char array

I'm an absolute beginner at C# and recently tried to create my own to do list as a console app. So what i want to do is give the user the option to chose with 'a' 'e' or 'd' and thought i could use that in an if statement. Heres how far i got:

    static void Main(string[] args)
    {
        Console.WriteLine("                           To-Do-List");
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Task capacity is 10");

        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("[a] Add Task");
        Console.WriteLine("[e] Edit Task");
        Console.WriteLine("[d] Delete Task");
        Console.ForegroundColor = ConsoleColor.White;

        
        Console.WriteLine("select action");
        char[] userAction = { 'a', 'e', 'd', };

        if (userAction[0])
        {

        }

    }
}

}

when i try to implement the userAction variable in the if condition it tells me it cant be converted into a boolean and since im not really confident with syntax and all that i dont know if thats even the right approach - do i have to use something else instead of an if statement? i would want the program to react for example if the user presses 'a' with something like Console.WriteLine("choose a name for your task");

Aucun commentaire:

Enregistrer un commentaire