samedi 26 septembre 2015

If user input is not a number C#

This is a very simple script I am trying to figure out and I have been looking for a simple answer and can't find it in the forums or in my C# book.

Console.Write("Enter a Number\n");
int input = Convert.ToInt32(Console.ReadLine()); //convert code to an integer

if (!Int32.IsNumber(input)) //if not a whole number input give an error
            {
                Console.WriteLine("Not an integer");
            }

It's just that simple what I'm trying to do. this is a snippet from a bigger code.

Aucun commentaire:

Enregistrer un commentaire