G98
G98

Reputation: 29

How to check whether the input is int or string

If the input is numerical then run numPalindrome().

If the input is alphabetical then run strPalindrome().

static void Main(string[] args)
{
    Console.Write("Enter your Input: ");
    var input = Console.ReadLine();
    if (What to do?????)
    {
        strPalindrome();
    }
    else
    {
        numPalindrome();
    }
}

Upvotes: 0

Views: 225

Answers (1)

Yash Gupta
Yash Gupta

Reputation: 2457

if(int.TryParse(input, out int value))
{
  // input is an int, call numPalindrome(value)
}
else
{
  // input is not an int, call strPalindrome()
}

Upvotes: 6

Related Questions