Kasutame pigem int.TryParse try catchi asemel

This commit is contained in:
Arti Zirk 2016-08-29 14:47:30 +03:00
parent a8c0abb420
commit 4576485075

View File

@ -18,18 +18,17 @@ namespace KonsooliDemo
Console.Write("Sisesta number: ");
var strNumber = Console.ReadLine();
try
int number;
if (int.TryParse(strNumber, out number))
{
int number = int.Parse(strNumber);
Console.WriteLine(number);
Console.WriteLine("Sisestasid numbri {0}", number);
}
catch (FormatException)
else
{
Console.WriteLine("See ei olnud number");
}
Console.Write("Vajuta mõnda klahvi lõpetamiseks");
Console.ReadKey();
}