我正在开展一个项目,是的。我很难理解如何传递用户输入并将其与数组一起存储。该项目是为了获得7天的高温和低温,并存储在不同的阵列中然后计算高等等。如何收集输入并将其存储在不同类的数组中?我想我差不多了,但不确定我哪里出错了
到目前为止我有这个但是得到错误:
无法将类型'int'隐式转换为'int []'
namespace Project_Console_3
{
class Program
{
static void Main(string[] args)
{
WeeklyTemperature Temp = new WeeklyTemperature();
int Count = 0;
while (Count < 7)
{
Console.WriteLine("Enter The High Temperature for Day {0}", Count+1);
Temp.HTemp1 =Console.ReadLine(); // save the number as a string number
Temp.HTemp = Convert.ToInt32(Temp.HTemp1); // change the string number to a integer as HTemp
Console.WriteLine("--------------------------------");//Draws a line
Console.WriteLine("Enter The Low Temperature for Day {0}", Count+1);
Temp.LTemp1 =Console.ReadLine(); // save the number as a string number
Temp.LTemp = Convert.ToInt32(Temp.LTemp1);
Console.WriteLine("--------------------------------");//Draws a line
Count = Count + 1;
Console.Clear();
}
}
}
}
WeeklyTemperature.cs
namespace Project_Console_3
{
class WeeklyTemperature
{
public int[] HTemp = new int[7];
public int[] LTemp = new int[7];
public string HTemp1;
public string LTemp1;
}
}
答案 0 :(得分:1)
看起来你需要做的就是改变这一行:
Temp.HTemp = Convert.ToInt32(Temp.HTemp1);
到
Temp.HTemp[Count] = Convert.ToInt32(Temp.HTemp1)
答案 1 :(得分:0)