早教吧作业答案频道 -->其他-->
C#的一道程序填空题求答案根据用户输入的身份证号,提取并输出出生年月日.在完成该程序功能时,需要定义一个类ID.classID{privatestringIDnumber;publicID(stringidnumber){this.IDnumber=idnumber.Trim();
题目详情
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;
}
根据用户输入的身份证号,提取并输出出生年月日.在完成该程序功能时,需要定义一个类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;
}
▼优质解答
答案和解析
第一空: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,'-'));
}
第二空: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,'-'));
}
看了 C#的一道程序填空题求答案根...的网友还看了以下:
下列现象不可能发生的是A.农历初一日月同升同落B.农历十五、十六日升月落C.二十二、二十三日出时月 2020-04-26 …
一项工程从3月1日开工,由甲乙合作,要求在5月1日竣工,这项工程如果甲单独做90天完成,乙单独做1 2020-05-23 …
2012年6月7日空中出现了“金星凌日”.其原因与日食成因相同,是光的现象.光在传播过程中(填“需 2020-07-03 …
五、根据课文内容填空。l、”曲阜和洛阳相距上千里,孔子风餐露宿,日夜兼程,几个月后,终于走到了洛五 2020-07-05 …
今年11月初以来,我国东北地区持续出现空气重污染过程,11月9日,黑吉辽大范围雾霾,其面积约为26 2020-07-28 …
丁丁同学参加学校组织的地理活动小组,他对以下四个城市的空气污染指数进行了记录:日期3月24日3月2 2020-08-01 …
2013年12月14日,在历经了数天“奔月”旅程和环月飞行之后,凝聚国人千年奔月梦想的嫦娥三号,以优 2020-11-08 …
一项工程从3月19日开工至11月20日完工,这项工程经过多少天?2007年小明满15岁,可是他一项工 2020-11-27 …
2012年6月1日.空降兵某部官兵使用新装备从260米超低空跳伞成功2012年6月1日.空降兵某部官 2020-12-04 …
巳月他会来求和吗?2014年5月2日15时37分甲午年戊辰月癸酉日庚申时甲子旬戌亥空月将:酉兄亥空⊙ 2021-01-09 …