C#的一道程序填空题求答案根据用户输入的身份证号,提取并输出出生年月日.在完成该程序功能时,需要定义一个类ID.clas

C#的一道程序填空题求答案
根据用户输入的身份证号,提取并输出出生年月日.在完成该程序功能时,需要定义一个类ID.class ID { private string IDnumber; public ID(string idnumber) { this.IDnumber = idnumber.Trim (); } //判断是否为有效的身份证号码:public bool IsValid(){……} //判断是否为有效的出生年月日:private bool IsValidBirthday(int year,int month,int day) {……} //获取出生日期 public DateTime getBirthday() {……} } 附录:目前的身份证号码有两种格式,一种是15位号码(如340501761217022),一种是18位号码(如340503197001090319).在15位号码中,第7—12位数字(如761217)表示持证人的出生时间(如1976年12月17日),在18位号码中,第7—14位数字(如19700109)表示持证人的出生时间(如1970年1月9日).请根据以上提示,补充下列下划线处的代码.//获取出生日期 public DateTime getBirthday() { DateTime Birthday; int year,month,day ; if (IsValid()) { if (IDnumber.Length == 15) { year = ________________(1)___________________; month = Int32.Parse(IDnumber.Substring(8,2)); day = _________________(2)___________________; Birthday = new DateTime(year,month,day); } else { year = ______________(3)___________________; month = ______________(4)___________________; day = ________________(5)___________________; Birthday = new DateTime(year,month,day); } } else Birthday = new DateTime(1,1,1); return Birthday;
}
plt1 1年前 已收到1个回答 举报

_yoshiko_ 幼苗

共回答了15个问题采纳率:93.3% 举报

第一空:Int32.Parse(“19”+IDnumber.Substring(6,2));
第二空:Int32.Parse(IDnumber.Substring(10,2));
第三空:Int32.Parse(IDnumber.Substring(6,4));
第四空:Int32.Parse(IDnumber.Substring(10,2));
第五空:Int32.Parse(IDnumber.Substring(12,2));
实际中我都不这样,我直接用
if(IDnumber.Length == 15)
{
return DateTime.Parse(("19"+IDnumber.Substring(6,6)).Insert(6,'-').Insert(4,'-'));
}
else
{
return DateTime.Parse(IDnumber.Substring(6,8).Insert(6,'-').Insert(4,'-'));
}

1年前

7
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.014 s. - webmaster@yulucn.com