Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

testDateParsing.cs

kyrathasoft Jul 21st, 2018 (edited) 75 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. using System;
  2. using TestInput;
  3. /*
  4. from Lesson 6 of C# console programming tutorial series at following URL:
  5. http://williammillerservices.com/windows-c-console-programming/
  6.  
  7. demonstrates functionality of helper method IsDate() that we added
  8. to tester.cs
  9.  
  10. GitHub gist -> https://gist.github.com/kyrathasoft/a2b9ed62224e7513161e43c96c5611b1
  11. Pastebin.com -> https://pastebin.com/Xfu5CuEE
  12. */
  13. namespace TestParsingOfStringToDateAndToInteger
  14. {
  15.     class MyTesterClass
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             //two test strings
  20.             string sTest1 = "the ninth of July, 2018";
  21.             string sTest2 = "7/9/2018";
  22.            
  23.             Console.WriteLine(); //print blank line...
  24.  
  25.             CanParseToDate(sTest1);
  26.             CanParseToDate(sTest2);            
  27.         }
  28.  
  29.         static void CanParseToDate(string p)
  30.         {
  31.             if (Tester.IsDate(p))
  32.             {
  33.                 /* We use a placeholder for variable 'p' value and we end
  34.                 the argument passed to WriteLine() with an extra line: \n
  35.                 to aid readability during program execution */
  36.                 Console.WriteLine("\"{0}\" can be parsed to a DateTime.\n", p);
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine("\"{0}\" cannot be parsed to a DateTime.\n", p);
  41.             }
  42.         }
  43.  
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top