簡體   English   中英

如何檢查 C# 中的返回方法是否為 integer

[英]How to check if a returned method in C# is an integer

我想循環一個方法,只要該方法在 C# 中不返回 integer。

     public static int isAnInt()
    {
        rQuit = Console.ReadLine();
        if (Int32.TryParse(rQuit, out isQuit) == false)
        {

            Console.WriteLine("Enter value again but as a number");
        }
        return isQuit;
    }

//雖然在main方法里面/

 while (int.TryParse(isAnInt() , out isQuit ) == false)
        {
            Console.WriteLine("This method is not an int try insert an int"); // For the method isAntInt I am trying to only
            //loop the method as 
            // long as it is not an integer.
        }
Console.WriteLine("Type something");
        //It saves input
        int thenumber;
        //Check if Input is a number
        while(!int.TryParse(Console.ReadLine(), out thenumber))
        {//If input not a number then output this
            Console.WriteLine("Not a number");
        }

給你 go

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM