Day 16: Exceptions - String to Integer

  • + 0 comments

    string S = Console.ReadLine();

    Console.WriteLine(S.Any(c=> !(c >= 48 && c <= 57) || c==' ')?"Bad String":S);

                                                 or
    

    Console.WriteLine(Int32.TryParse(S, out int result)?result:"Bad String");