如何检查C#中返回的方法是否为整数

如何检查C#中返回的方法是否为整数,c#,loops,methods,return-type,C#,Loops,Methods,Return Type,我想循环一个方法,只要该方法不返回C#中的整数 //而在主方法中/ 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 me

我想循环一个方法,只要该方法不返回C#中的整数

//而在主方法中/

 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.
        }

现在开始

如果你能提供一个(编译的)函数,那就太棒了。另外,问问自己为什么有两个不同的
int.TryParse
调用。如果控制台输入不是数字,
isAnInt
将返回什么。如果你能同时回答这两个问题,你就会意识到你犯的错误)。我也很惊讶代码甚至可以编译,但我们将把它放在一边。
isAnInt
被定义为返回一个
int
。它只能返回一个
int
。因此,当您调用
int.TryParse(isAnInt()…
时,您正试图解析一些已经是
int
的内容。您需要将循环推入执行原始解析的代码中。这里的
out-var-thenumber
不是更好吗?不,为什么?我一直以这种方式使用它,因为它更简洁(您不需要重复
int
number
 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");
        }