如何编写一个while循环来验证用户输入正值

如何编写一个while循环来验证用户输入正值

问题描述:

犯了大量错误,可能做错了。我正在使用visual studio和C#语言。 app.config

Getting a ton of errors and probably doing this all wrong. I'm using visual studio and C# language. app.config

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace positive
{
    class Program
    {
        static void Main(string[] args)
        {
            System.out.print("Enter a positive integer: ");
            number = scan.nextInt();
            while (number <= 0)
            
                System.out.print("Enter a positive integer: ");
                number = scan.nextInt();
        }
    }
}




您确定代码内容不是
Java
的?但不,你甚至没有声明变量。

Are you sure the code content is not Java? But no, you didn't even declare the variable.

顺便说一句,你需要了解Console.ReadLine(),Console.WriteLine()和  UInt32.TryParse()

Btw, you need to learn about Console.ReadLine(), Console.WriteLine() and UInt32.TryParse() .