C# 我的二传手赢了;当int超出我的else if语句的界限时,t返回0

C# 我的二传手赢了;当int超出我的else if语句的界限时,t返回0,c#,arrays,class,object,constructor,C#,Arrays,Class,Object,Constructor,我的构造函数应该返回给定的分数,只要分数在0到300之间。如果分数超出此边界,则应返回值0。但是,它会返回我给类的值,而不是我设置的值。 主程序 namespace ClassScores { class Program { static void Main(string[] args) { int runningTotal = 0; double average = 0;

我的构造函数应该返回给定的分数,只要分数在0到300之间。如果分数超出此边界,则应返回值0。但是,它会返回我给类的值,而不是我设置的值。 主程序

namespace ClassScores
{
     class Program
     {
         static void Main(string[] args)
         {
             int runningTotal = 0;
             double average = 0;
             .....
             Bowler Jesus = new Bowler("Jesus", 450);
             bowlers[3] = Jesus;
             for (int i=0; i <= 4; i++)
             {
             runningTotal=runningTotal + bowlers[i].Score;
             }
             average = Convert.ToDouble(runningTotal/5);
             Console.WriteLine("The average bowler score is " + average);

         }
     }
 }
名称空间类分数
{
班级计划
{
静态void Main(字符串[]参数)
{
int runningTotal=0;
双平均=0;
.....
保龄球手耶稣=新保龄球手(“耶稣”,450);
保龄球手[3]=耶稣;

对于(int i=0;i=0&&Score您不是在范围检查
,这是新值。您是在范围检查
——旧值。这是您打算执行的操作:

     set
     {
         if (value >= 0 && value <= 300)
         {
             this.score = value;
         }
         else
         {
             this.score = 0;
         }
     }
set
{

如果(value>=0&&value使用
?:
操作符,这里就很好了
     set
     {
         if (value >= 0 && value <= 300)
         {
             this.score = value;
         }
         else
         {
             this.score = 0;
         }
     }
     set
     {
         this.score = (value >= 0 && value <= 300)
                          ? value
                          : 0;
     }