How to loop a Console.ReadLine?

后端 未结 5 2027
醉酒成梦
醉酒成梦 2021-01-06 13:31

I cannot figure out how to read user-input in a loop (with Console.ReadLine). I\'m trying to create a note that lets me store what ever the user inputs, and exi

5条回答
  •  春和景丽
    2021-01-06 14:09

    You need List of Notes in order to add as many notes as you want. Additionally, you need to first save ReadLine input check if the user really asked to exit otherwise keep adding notes.

    var myNotes = new List();
    var firstNote = new Note();
    firstNote.addText("Hi there");
    
    Note note;
    while (true)
    {
        var input = Console.ReadLine();
        if (input.Equals("exit", StringComparison.OrdinalIgnoreCase))
        {
            break;
        }
        note = new Note();
        note.addText(input);
        myNotes.Add(note);
    }
    

提交回复
热议问题