Quantcast
Channel: switch statement - Stack Overflow
Browsing latest articles
Browse All 6 View Live

Answer by Robert Cartaino for switch statement

I think your code would be easier to learn and understand if you did not use exceptions to test your numbers. Try using int.TryParse() instead (TryParse() on MSDN). TryParse() returns true (or false)...

View Article



Answer by UncleO for switch statement

Move the try/catch block inside the loop. Robert Harvey's suggestion of the do/while loop is good, too. int enterYourNumber; char shortLetter; do { try { Console.WriteLine("Please enter the integer:...

View Article

Answer by Doug L. for switch statement

Since you are learning, you might also consider handling the error differently. Have a look at the SO question: In C# should try-catch be used for is-numeric testing? for more ideas and discussion.

View Article

Answer by billjamesdev for switch statement

Robert's is a start, but perhaps we still want to try catch...Replace your main function with:do{ enterYourNumber = GetNumber(); WriteNumber(enterYourNumber); Console.WriteLine("Do you still want to...

View Article

Answer by Robert Harvey for switch statement

do{ Console.WriteLine("Please enter the integer: "); enterYourNumber = Convert.ToInt32(Console.ReadLine()); WriteNumber(enterYourNumber); Console.WriteLine("Do you still want to enter a number? Y/N");...

View Article


switch statement

I'm practising the "Switch Loop" in a program. And I'm making a code where a user can input the integer and after the user will input the integer it will also display what the user just typed in. Now...

View Article
Browsing latest articles
Browse All 6 View Live


Latest Images