Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# checking if a value is a int


using System;

namespace Help
{
    class Program
    {
        static void Main(string[] args)
        {
            string text1 = "Hello";
            string text2 = "29";

            if (CheckInt(text1) == true) // if text 1 is a int, it's going to print : Text 1 is a int
            {
                Console.WriteLine("Text 1 is a int");
            }
            else if (CheckInt(text2) == true) // if text 2 is a int, which is the case, it's going to print : Text 2 is a int
            {
                Console.WriteLine("Text 2 is a int");
            }
        }
        public static bool CheckInt(string input)
        {
            int number = 0;
            return int.TryParse(input, out number);
        }
    }
}
 
PREVIOUS NEXT
Tagged: #checking #int
ADD COMMENT
Topic
Name
4+2 =