c#创建只读属性赋值问题

2024-11-28 23:46:45
推荐回答(3个)
回答1:

既然是只读,那只能直接给它赋值了。如果你还要用表达式改,就要可读写。
set
{
sumScore = value;MathScore + EnglishScore + PhysicScore;
}
main:
sumScore = MathScore + EnglishScore + PhysicScore;

回答2:

很简单

private int sumScore;
public int SumScore
{
get
{
sumScore = MathScore + EnglishScore + PhysicScore;
return sumScore;
}
}

回答3:

只读了,还能赋值啊,你这是逻辑错误