Advertisement
kyrathasoft

tester1

Jul 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. /* a helper class, Tester, begun in Lesson 5 of intro C# console
  3. programming series found at the following URL:
  4. http://williammillerservices.com/windows-c-console-programming/
  5. note: to use, you would reference the file containing this code
  6. from your primary program file. If you have the following program...
  7. GitHub gist -> https://gist.github.com/kyrathasoft/35357f7fee1c427693323286111e5e43
  8. Pastebin.com -> https://pastebin.com/edit/K6D01kgv
  9.  
  10. using System;
  11. using TestInput;
  12.  
  13. namespace MyNS{
  14.     class MyCls{
  15.         public static void Main(){
  16.             string sNum = "4";
  17.             if(Tester.IsInteger(sNum)){
  18.                 Console.WriteLine("Yes, we can parse {0} to an int.", sNum);
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. ...and if above program named test.cs and below is tester.cs and in
  25. same directory, then we'd compile like so:
  26.  
  27. csc /out:test.exe test.cs tester.cs
  28.  
  29. Running resulting test.exe would produce: Yes, we can parse 4 to an int.
  30.  
  31. Or, we could make tester.cs code into DLL via:
  32. csc /t:library tester.cs
  33.  
  34. ...and then compile like so:
  35. csc /r:tester.dll test.cs
  36.  
  37. */
  38.  
  39.  
  40. namespace TestInput
  41. {
  42.     public class Tester
  43.     {
  44.         public static bool IsInteger(string p)
  45.         {
  46.             bool result = false;
  47.             int i;
  48.  
  49.             if (int.TryParse(p, out i))
  50.             {
  51.                 result = true;
  52.             }
  53.  
  54.             return result;
  55.         }
  56.  
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement