Last active
July 21, 2018 17:14
-
-
Save kyrathasoft/35357f7fee1c427693323286111e5e43 to your computer and use it in GitHub Desktop.
Tests if integer, if date, has some date manipulation methods. The helper methods in class Tester were developed as part of lessons associated with the following online tutorial series: http://williammillerservices.com/windows-c-console-programming/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/* a helper class, Tester, begun in Lesson 5 of intro C# console | |
programming series found at the following URL: | |
http://williammillerservices.com/windows-c-console-programming/ | |
note: to use, you would reference the file containing this code | |
from your primary program file. If you have the following program... | |
GitHub gist -> https://gist.github.com/kyrathasoft/35357f7fee1c427693323286111e5e43 | |
Pastebin.com -> https://pastebin.com/edit/K6D01kgv | |
using System; | |
using TestInput; | |
namespace MyNS{ | |
class MyCls{ | |
public static void Main(){ | |
string sNum = "4"; | |
if(Tester.IsInteger(sNum)){ | |
Console.WriteLine("Yes, we can parse {0} to an int.", sNum); | |
} | |
} | |
} | |
} | |
...and if above program named test.cs and below is tester.cs and in | |
same directory, then we'd compile like so: | |
csc /out:test.exe test.cs tester.cs | |
Running resulting test.exe would produce: Yes, we can parse 4 to an int. | |
Or, we could make tester.cs code into DLL via: | |
csc /t:library tester.cs | |
...and then compile like so: | |
csc /r:tester.dll test.cs | |
*/ | |
namespace TestInput | |
{ | |
public class Tester | |
{ | |
public static bool IsInteger(string p) | |
{ | |
bool result = false; | |
int i; | |
if (int.TryParse(p, out i)) | |
{ | |
result = true; | |
} | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment