我的 Int 变量出现意外符号错误

问题描述

using System;
using static System.Console;
using System.Globalization;
class MoveEstimator
{
   static void Main()
   {
     string entry; 
     int base;
     base = 200;
     int rph = 150;
     int rpm = 2;
     int input;
     int hours; 
     int miles; 
     int total;
     
     WriteLine ("Enter number of hours for job >>");
     entry = ReadLine ();
     WriteLine ("Enter number of miles for job >>");
     string entryii = ReadLine ();

     hours = Convert.ToInt32(entry);
     miles = Convert.ToInt32(entryii);

     total = (base + rph*hours + rpm*miles);

  WriteLine ("For a move taking{0} hours and going {1}miles the estimate is {2}",hours,miles,total.ToString("C",CultureInfo.GetCultureInfo("en-US")));
     


   }
}

我不断收到错误消息,指出我的整数变量“base”是一个意外符号。我所做的只是说 int base;。怎么这么不对劲。每次我引用它时都会出错。

解决方法

首先,欢迎来到 Stack Overflow!

base 是 C# 中的保留关键字,因此您应该为此变量指定任何其他名称,例如 initialDistance))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...