private void AddSentenceCommandTask() { Console.Write("請輸入新文句ID(輸入cancel取消): "); int sentenceID = 0; string inputString = Console.ReadLine(); if (inputString != "cancel") { while (inputString != "cancel" && (!int.TryParse(inputString, out sentenceID) || editingParagraph.ContainsSentence(sentenceID))) { if (editingParagraph.ContainsSentence(sentenceID)) { Console.Write("ID已存在 請輸入新文句ID(整數)(輸入cancel取消): "); } else { Console.Write("不合法的輸入 請輸入新文句ID(整數)(輸入cancel取消): "); } inputString = Console.ReadLine(); } if (inputString != "cancel") { Console.Write("請輸入角色名稱: "); string speakerName = Console.ReadLine(); editingParagraph.AddSentence(new Sentence(sentenceID, speakerName)); ViewCommandTask(); } } }