111,126
社区成员
发帖
与我相关
我的任务
分享
int a;
a = Convert.ToInt32(Console.ReadLine());
using System;
using System.IO;
namespace Demo
{
internal class Program
{
private static void Main(string[] args)
{
try
{
int a = GetInput();
int b = GetInput();
Console.WriteLine("Sum = {0}", a + b);
}
catch (InvalidDataException ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
private static int GetInput()
{
string str = Console.ReadLine();
int a;
if (int.TryParse(str, out a))
{
return a;
}
throw new InvalidDataException("The input is not a number");
}
}
}