我希望我的程序驗證日期格式爲mm/dd/yyyy
。我不想使用任何throw/catch塊。格式化日期時沒有得到預期的輸出
class FunWithScheduling
{
public void AddView()
{
...
...
Console.WriteLine("Enter the Date Scheduled For the Meeting:");
string Date = Console.ReadLine();
DateTime date = DateTime.Parse(Date);
string formatted = date.ToString("MM-dd-yyyy");
if (Date != formatted)
Console.WriteLine("Invalid Choice");
...
...
}
static void Main()
{
FunWithScheduling a = new FunWithScheduling();
a.AddView();
}
}