Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using TestInput;
- /*
- from Lesson 5 of C# console programming tutorial series at following URL:
- http://williammillerservices.com/windows-c-console-programming/
- demonstrates while loop and safe parsing of string to integer. To
- compile, requires tester1.cs
- GitHub gist -> https://gist.github.com/kyrathasoft/619b3addf6d7204d325a04ff77859a77
- Pastebin.com -> https://pastebin.com/3N76Jz03
- Dependencies: tester1.cs
- -> https://gist.github.com/kyrathasoft/35357f7fee1c427693323286111e5e43
- */
- namespace GetInteger4FromKeyboard
- {
- class CanIHavvaFourPlease
- {
- static void Main(string[] args)
- {
- //var to hold keyboard input
- string sData = String.Empty;
- //var to hold sData parsed to an Int
- int i = 0;
- /* our loop will be entered at LEAST
- once; initializing i to zero sees to
- that... */
- while (i != 4)
- {
- Console.Write("Please enter integer 4: ");
- sData = Console.ReadLine();
- if (Tester.IsInteger(sData))
- {
- i = Int32.Parse(sData);
- }
- }
- Console.WriteLine("Thanks for entering integer {0}.",
- i.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement