Kasutame pigem int.TryParse try catchi asemel
This commit is contained in:
parent
a8c0abb420
commit
4576485075
@ -18,16 +18,15 @@ namespace KonsooliDemo
|
|||||||
Console.Write("Sisesta number: ");
|
Console.Write("Sisesta number: ");
|
||||||
var strNumber = Console.ReadLine();
|
var strNumber = Console.ReadLine();
|
||||||
|
|
||||||
try
|
int number;
|
||||||
|
if (int.TryParse(strNumber, out number))
|
||||||
{
|
{
|
||||||
int number = int.Parse(strNumber);
|
Console.WriteLine("Sisestasid numbri {0}", number);
|
||||||
Console.WriteLine(number);
|
|
||||||
}
|
}
|
||||||
catch (FormatException)
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("See ei olnud number");
|
Console.WriteLine("See ei olnud number");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Console.Write("Vajuta mõnda klahvi lõpetamiseks");
|
Console.Write("Vajuta mõnda klahvi lõpetamiseks");
|
||||||
|
Loading…
Reference in New Issue
Block a user