Advertisement
kyrathasoft

parse to int may throw exception

Jul 21st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2. /*
  3. from Lesson 4 of C# console programming tutorial series at following URL:
  4. http://williammillerservices.com/windows-c-console-programming/
  5. demonstrates potential run-time error in that user may fail to input
  6. a value that is parseable to an integer
  7. GitHub gist -> https://gist.github.com/kyrathasoft/2bc097e9e9a465f7d4388e46ed8798cb
  8. Pastebin.com -> https://pastebin.com/7uPxzcKG
  9. */
  10. namespace MyNamespace {
  11.     class MyClass {
  12.         static void Main(){
  13.             Console.Write("Please enter an integer: ");
  14.             string sNum = Console.ReadLine();
  15.             int iNum = Int32.Parse(sNum);
  16.             Console.WriteLine("You entered: {0}", iNum.ToString());    
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement