private void AddSectionCommandTask() { Console.Write("請輸入新章節ID(輸入cancel取消): "); int sectionID = 0; string inputString = Console.ReadLine(); if (inputString != "cancel") { while (inputString != "cancel" && (!int.TryParse(inputString, out sectionID) || editingChapter.ContainsSection(sectionID))) { if (editingChapter.ContainsSection(sectionID)) { Console.Write("ID已存在 請輸入新章節ID(整數)(輸入cancel取消): "); } else { Console.Write("不合法的輸入 請輸入新章節ID(整數)(輸入cancel取消): "); } inputString = Console.ReadLine(); } if (inputString != "cancel") { Console.Write("請輸入章節名稱: "); string sectionName = Console.ReadLine(); editingChapter.AddSection(new Section(sectionID, sectionName)); ViewCommandTask(); } } }