Difference between revisions of "2020 - Validation on entering text instead of numerical values"
(Created page with "<syntaxhighlight lang=csharp> while (true) { Console.Write("Enter X coordinate for new outlet: "); try...") |
|||
Line 1: | Line 1: | ||
<syntaxhighlight lang=csharp> | <syntaxhighlight lang=csharp> | ||
while (true) | while (true) | ||
− | + | { | |
− | + | Console.Write("Enter X coordinate for new outlet: "); | |
− | + | try | |
− | + | { | |
− | + | x = Convert.ToInt32(Console.ReadLine()); | |
− | + | break; | |
− | + | } | |
− | + | catch | |
− | + | { | |
− | + | Console.WriteLine("invalid data"); | |
− | + | } | |
− | + | } | |
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 16:40, 9 December 2019
while (true)
{
Console.Write("Enter X coordinate for new outlet: ");
try
{
x = Convert.ToInt32(Console.ReadLine());
break;
}
catch
{
Console.WriteLine("invalid data");
}
}