static void Main(string[] args) { Console.Write("Enter number: "); string input = Console.ReadLine(); ParseIntResult result = CustomParseInt(input); if (result.Success) { Console.WriteLine("You typed the number: " + result.Value); } else { Console.WriteLine("You did not type a valid number!"); } }
public static ParseIntResult CustomParseInt(string s) { try { ParseIntResult r = new ParseIntResult { Value = int.Parse(s), Success = true }; return(r); } catch { ParseIntResult r = new ParseIntResult { Value = 0, Success = false }; return(r); } }