YTU OJ 3486 问题 A: 简单类及成员实例(C#)
using System;
namespace sample{
class Student {
public string studentid;//学号
public string studentname;//姓名
private string birthplace;//籍贯
private DateTime birthdate;//出生日期
/
//请填写代码,实现类的无参和有参构造函数、
//属性StudentId、StudentName、BirthPlace、BirthDate、Age
/
}
class Program
{
static void Main(string[] args)
{
Student zs = new Student("201753501234", "zs");
zs.BirthDate = DateTime.Parse("1988-12-10");
zs.BirthPlace = "jinan";
string s = "name:{0},no:{1},native:{2},age:{3}";
Console.WriteLine(s,zs.StudentName,zs.StudentId,zs.BirthPlace,zs.Age);
}
}
}
只需要提交补充内容
private int age;
public int Age
{
get
{
return this.age = (2021 - Convert.ToInt32(birthdate.Year));
}
}
public string StudentId
{
get
{
return studentid;
}
set
{
studentid = value;
}
}
public string StudentName
{
get
{
return studentname;
}
set
{
studentname = value;
}
}
public string BirthPlace
{
get
{
return birthplace;
}
set
{
birthplace = value;
}
}
public DateTime BirthDate
{
get
{
return birthdate;
}
set
{
birthdate = value;
}
}
public Student(string dateTime,string name)
{
this.studentid=dateTime;
this.studentname = name;
}