0

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();
    }
}
3
  • 3
    Maybe use int.TryParse? Commented Aug 16, 2021 at 11:52
  • 3
    int.TryParse might helpful Commented Aug 16, 2021 at 11:52
  • 1
    Int.TryParse() but could use RegEx. Commented Aug 16, 2021 at 12:12

1 Answer 1

6
if(int.TryParse(input, out int value))
{
  // input is an int, call numPalindrome(value)
}
else
{
  // input is not an int, call strPalindrome()
}
Sign up to request clarification or add additional context in comments.

3 Comments

^^That. The only way to know if it is a int, is to try to parse it to int. | Just be warned, that value is always set - TryParse defaults to setting it to 0 in case the parsing fails. So do not use it by accident.
@Christopher - that's correct. Thank you for adding this point.
int.Parse will of course also accept negtive number. If you don't want these, use uint.TryParse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.