Bị lỗi datetime khi build

Tại sao em code dòng:

Console.OutputEncoding = Encoding.UTF8;

Console.WriteLine("Mời bạn nhập vào năm sinh: ");
string s= Console.ReadLine();
DateTime birthday = DateTime.Parse(s);
Console.WriteLine("Bạn sinh ngày: " + birthday.Day);
Console.WriteLine("Bạn sinh tháng: "+birthday.Month);
Console.WriteLine("Bạn sinh năm: " + birthday.Year);
Console.ReadLine();

Lúc em nhập dữ liệu thì nó hiện bảng thồng báo : An unhandled exception of type ‘System.FormatException’ occurred in mscorlib.dll
Additional information: String was not recognized as a valid DateTime.
Mong mấy anh giúp em a. Em cảm ơn nhiều !

String bạn nhập sai cấu trúc, xem ví dụ tại đây:

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?