我是编程的新手,我正在尝试创建一个循环,其中while条件基于变量但是我不知道它的正确语法。 这就是我想要做的,即使它可能不被允许......我想。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
float totalArea, areaUnbuilt;
while (!float.TryParse(Console.ReadLine(), out totalArea, out areaUnbuilt))
{
Console.Clear();
Console.WriteLine("Insert total area in square meters:");
float.TryParse(Console.ReadLine(), out totalArea);
Console.WriteLine("Insira are not built in square meters:");
float.TryParse(Console.ReadLine(), out areaUnbuilt);
}
}
}
}
答案 0 :(得分:0)
您无法使用TryParse取回两个值。而是将代码更改为do..while循环
bool isArea = true;
bool isUnbuilt = true;
do
{
Console.Clear();
Console.WriteLine("Insert total area in square meters:");
isArea = float.TryParse(Console.ReadLine(), out totalArea);
Console.WriteLine("Insert area not built in square meters:");
isUnbuilt = float.TryParse(Console.ReadLine(), out areaUnbuilt);
} while( !isArea || !isUnbuilt);