Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- /* a helper class, Tester, begun in Lesson 5 and now extended in
- Lesson 6 of intro C# console programming series found at the
- following URL:
- http://williammillerservices.com/windows-c-console-programming/
- GitHub gist -> https://gist.github.com/kyrathasoft/1a2b341e6ae8e97c91c68e51082c1409
- Pastebin.com -> https://pastebin.com/nKVkikZ8
- note: to use, you would reference the file containing this code
- from your primary program file. If you have the following program...
- 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;
- }
- }
- public static int GetDifferenceInYears(DateTime startDate, DateTime endDate)
- {
- //Excel documentation says "COMPLETE calendar years in between dates"
- int years = endDate.Year - startDate.Year;
- if (startDate.Month == endDate.Month &&// if the start month and the end month are the same
- endDate.Day < startDate.Day// AND the end day is less than the start day
- || endDate.Month < startDate.Month)// OR if the end month is less than the start month
- {
- years--;
- }
- return years;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement