Title description
Simple class and member instance. Define the class Student as shown in the figure below, fill in the missing code according to the figure below and the code given.
using System;
namespace sample{ class Student { public string studentid;//Student ID public string studentname;//Name private string birthplace;//Hometown private DateTime birthdate;//Birth date / //Please fill in the code to achieve class no Parameter and parameterized constructor, //attributes 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);
}
}
}
enter
no
Output
Output name, student number, hometown, age and other information
Sample input
copy
no
Sample output
name:zs,no:201753501234,native:jinan,age:33
prompt
1. Age is a read-only attribute,
2. StudentId, Name StudentName, Date of Birth, BirthPlace, and BirthPlace are general attributes;
3. There are two types of constructors: with or without parameters and with parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
class Student
{
public string studentid;//学号
public string studentname;//姓名
private string birthplace;//籍贯
private DateTime birthdate;//出生日期
/
//请填写代码,实现类的无参和有参构造函数、
public Student() { }
public Student(string id,string name){
studentid=id;
studentname=name;
}
//属性StudentId、StudentName、BirthPlace、BirthDate、Age
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 int Age{
get{
return 33;
}
}
/
}
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);
}
}
}