因此,我正在制作一个窗体,为学生的详细信息和国际学生提供一个单独的类。我需要验证我的学生/国际学生的年份分数是否大于0且小于100.解析和验证数字和日期时间输入
我也想要将出生日期显示为dd/mm/yyyy,但目前显示为那加上时间。
我将包括下面的代码:
第一出生日期
student1.DateOfBirth = DateTime.Parse(txtDateofbirth.Text).Date;
if (string.IsNullOrEmpty(txtDateofbirth.Text))
{
MessageBox.Show("Please enter a DoB");
}
现在的年马克
try // Trying to do the thing in the curly braces
{
student1.YearMark = Int32.Parse(txtYearMark.Text);
}
catch (Exception) // If it doesn't work skip the crash and print this
{
MessageBox.Show("The Year mark must be a number and can't be empty");
}
这不是一个完整的答案,但请尝试使用日期时间的的TryParse方法,然后看所产生的各种属性DateTime实例。 – MNGwinn