willsmythe37
9/28/2018 - 2:49 PM

C# Using Method Libraries 2

A good example of this in action

using System;
class MethodLibraries
{
 static string readString(string prompt)
 {
 string result;
 do
 {
 Console.Write(prompt);
 result = Console.ReadLine();
 } while (result == "");
 return result;
 }
 static int readInt(string prompt, int low, int high)
 {
 int result;
 do
 {
 string intString = readString(prompt);
 result = int.Parse(intString);
 } while ((result < low) || (result > high));
 return result;
 }
 public static void Main()
 {
 string name;
 name = readString("Enter your name : ");
 Console.WriteLine("Name: " + name);
 int age;
 age = readInt("Enter your age : ", 0, 100);
 Console.WriteLine("Age: " + age);
 }
}