Parse and TryParse
Parse throws an exception on failure; TryParse returns false.
string input = "456";if (int.TryParse(input, out int result))Console.WriteLine($"Parsed: {result}");elseConsole.WriteLine("Invalid");Run the Application
Section titled “Run the Application”dotnet runResult
Section titled “Result”Parsed: 456