修改下面代码 C#实现对基类的属性重载

在Undergraduat和Graduate中分别重载Grade属性,强制要求Undergraduate的年级范围在1—4之间,而Graduate的年级范围在1—3之间u... 在Undergraduat和Graduate中分别重载Grade属性,强制要求Undergraduate的年级范围在1—4之间,而Graduate的年级范围在1—3之间
using System;
using System.Collections.Generic;
using System.Text;

namespace L7_3
{
class Student
{
private int _id;
public int ID
{
get
{
return _ID;
}
set
{
_ID = value;
}
}
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
private string _gender;
public string Gender
{
get
{
return _gender;
}
set
{
_gender = value;
}
}
private int _class;
public int Class
{
get
{
return _class;
}
set
{
_class = value;
}
}
private int _grade;
public virtual int Grade
{
get
{
return _grade;
}
set
{
_name = value;
}
}

}
class Undergraduate : Student
{
private string _department;
public string Department
{
get
{
return _department;
}
set
{
_department = value;
}
}
}
class Graduate : Student
{
private string O_tutor;
public string Tutor
{
get
{
return O_tutor;
}
set
{
O_tutor = value;
}
}
}
}
展开
 我来答
司琅0Iid5b
2010-11-17 · TA获得超过802个赞
知道小有建树答主
回答量:319
采纳率:0%
帮助的人:619万
展开全部
你好,根据你的需求,重写了Grade属性:

// copyright @ quark
// date: 2010-11-16

using System;
using System.Collections.Generic;
using System.Text;

namespace L7_3
{
class Student
{
private int _id;
public int ID
{
get
{
return _id;
}
set
{
_id = value;
}
}
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
private string _gender;
public string Gender
{
get
{
return _gender;
}
set
{
_gender = value;
}
}
private int _class;
public int Class
{
get
{
return _class;
}
set
{
_class = value;
}
}
private int _grade;
public virtual int Grade
{
get
{
return _grade;
}
set
{
_grade = value;
}
}

}
class Undergraduate : Student
{
private string _department;
public string Department
{
get
{
return _department;
}
set
{
_department = value;
}
}

public override int Grade
{
get
{
return base.Grade;
}
set
{
if (value >=1 && value <=4)
{
base.Grade = value;
}
}
}
}
class Graduate : Student
{
private string O_tutor;
public string Tutor
{
get
{
return O_tutor;
}
set
{
O_tutor = value;
}
}

public override int Grade
{
get
{
return base.Grade;
}
set
{
if (value >= 1 && value <= 3)
{
base.Grade = value;
}
}
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式