C# 设计一个学生类,字段:姓名(可读写),出生日期(只读),成绩(可读写),且为三个字段附初值的构造方法
3个回答
2014-06-07 · 知道合伙人数码行家
关注
展开全部
代码如下:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Student stu = new Student("小明", DateTime.Now, 99);
MessageBox.Show(string.Format("姓名:{0}\r\n出生日期:{1:yyyy-MM-dd}\r\n成绩:{2}\r\n", stu.Name, stu.Birth, stu.Course));
}
}
public class Student
{
public Student(string name,DateTime birth,int course)
{
this.Name = name;
this.Birth = birth;
this.Course = course;
}
public string Name { get; set; }
public DateTime Birth { get; private set; }
public int Course { get; set; }
}
效果:
如有疑问,继续追问。
展开全部
public class Student
{
private string name ;
private DateTime birthday;
private double score;
public Student(string name,DateTime birthday,double score)
{
this.name = name;
this.birthday = birthday;
this.score = score;
}
public string Name
{
get{return this.name;}
set{this.name = value;}
}
public string Birthday
{
get{return this.name;}//只读
}
public string Score
{
get{return this.score;}
set{this.score= value;}
}
}
{
private string name ;
private DateTime birthday;
private double score;
public Student(string name,DateTime birthday,double score)
{
this.name = name;
this.birthday = birthday;
this.score = score;
}
public string Name
{
get{return this.name;}
set{this.name = value;}
}
public string Birthday
{
get{return this.name;}//只读
}
public string Score
{
get{return this.score;}
set{this.score= value;}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Student
{
private string xingming;
public string name
{
get
{
return xingming;
}
set
{
xingming = value;
}
}
private string chusheng;
public string birthday
{
get
{
return chusheng;
}
}
private string chengji;
public string grade
{
get
{
return chengji;
}
set
{
chengji = value;
}
}
public void Student(string name, string birthday, string grade)
{
xingming = name;
chusheng = birthday;
chengji = grade;
}
}
{
private string xingming;
public string name
{
get
{
return xingming;
}
set
{
xingming = value;
}
}
private string chusheng;
public string birthday
{
get
{
return chusheng;
}
}
private string chengji;
public string grade
{
get
{
return chengji;
}
set
{
chengji = value;
}
}
public void Student(string name, string birthday, string grade)
{
xingming = name;
chusheng = birthday;
chengji = grade;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询