使用c#构造函数时,为什么属性set中的判断条件无效

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespa... using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _02构造方法
{
class student
{

public student(string name, char sex, double chinese,double english)
{
this.name = name;
this.Sex = sex;
this.chinese = chinese;
this.english = english;
}
private string name;
public string Name
{
get { return name; }
set
{
if (value != "张三" && value != "李四")
{
name = "匿名";
}
else
{
name = value;
}
}
}
private char sex;
public char Sex
{
get { return sex; }
set {
if (value != '男' && value != '女')
{
sex = '男';
}
else
{
sex = value;
}
}
}
private double chinese;
public double Chinese
{
get { return chinese; }
set
{
if (value < 0 || value > 100)
{
chinese = 0;
}
else
{
chinese = value;
}
}
}
private double english;
public double English
{
get { return english; }
set { english = value; }
}
public void sayhello()
{
Console.WriteLine("我的名字叫{0},今年{1}岁了,是位{2}生!",name ,age ,sex );
}
public void score()
{
Console.WriteLine("我的语文成绩为{0},数学成绩为{1},英语成绩为{2},平均成绩为{3}!",chinese ,match ,english ,(chinese +match +english )/3);
}
}
}

static void Main(string[] args)
{
student stu2 = new student("李四", '女', -78, 90);
stu.sayhello();
stu.score();
stu2.sayhello();
stu2.score();
Console.ReadKey();
}
为什么-78输出时没有变为0?
展开
 我来答
画角连城
2012-07-22 · TA获得超过775个赞
知道小有建树答主
回答量:224
采纳率:0%
帮助的人:316万
展开全部
你把构造函数里的这句话:
this.chinese = chinese;

改为:
this.Chinese = chinese;
只改了一个字母,原因在于没改前,你是对成员变量在赋值,根本没执行到Chinese属性的set访问器。
追问
谢谢了
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式