C#如何确定输入了多少数字?
如何查找输入的数字数量C#如何确定输入了多少数字?,c#,C#,如何查找输入的数字数量 static void Main(string[] args) { string x; double t, s = 1; while ((x = Console.ReadLine()) != null) { } 要将数字输入为double,可以使用double.TryParse将“x”转换为“t”,然后以某种方式对其进行操作。如果
static void Main(string[] args)
{
string x;
double t, s = 1;
while ((x = Console.ReadLine()) != null)
{
}
要将数字输入为double,可以使用double.TryParse将“x”转换为“t”,然后以某种方式对其进行操作。如果你想要更具体的东西,你需要分享你想要做的事情(预期输入/预期输出)。你的英语“输入了多少数字”不清楚
static void Main(string[] args)
{
string x;
double t,tot=0, s = 1;
while ((x = Console.ReadLine()) != null)
{
if(double.TryParse(x,out t))
{
//t is now the number entered as a double -- process
tot+= t;
Console.WriteLine(s==1?"Please enter your second number":"The sum of your "+s.ToString()+" numbers is "+tot.ToString("N0"));
s++;
}else{
Console.WriteLine("You may only enter numbers. Please try again.\n");
}
}
您的问题不清楚,请使用说明输入解释问题的说明(超过9个单词)。是否要将
x
转换为数字并存储在t
中?或者验证x是一个有效的数字?很抱歉我的英语不好。这是我的密码。例如,我输入了“5”“4”“3”个数字。结果是60。在下一行中,我需要显示我为这个例子输入了多少数字,我需要显示“3”好的-我刚刚编辑了我的答案,做了我认为你们在寻找的事情。这就是你想要它做的吗?