c# - Why does the first Date String return false? -


i'm trying parse strings see if valid dates. i'm using few cultures , formats cover different variations of dates.

functionality wise, code below seems work fine, can't grasp why first string returns 'false'. not valid date string of mm-dd-yyyy format?.

public class program         {             public static cultureinfo frc = new cultureinfo("fr-fr");             public static cultureinfo usc = new cultureinfo("en-us");             public static cultureinfo gbc = new cultureinfo("en-gb");             public static cultureinfo inc = new cultureinfo("en-in");             public static string[] dateformats = { "d-m-yy", "dd-mm-yyyy","d-m-yyyy", "dd mmmm yyyy", "dmyy", "dmyyyy", "d/m/yy", "d/m/yyyy" };             public static void main()             {                 bool isvaliddate = false;                  string[] listofdates = { "10-23-2016", "3-01-93", "14-4-1973", "22 juin 2015", "mama, i'm comin home!", "06/06/06" };                 foreach (var date in listofdates)                 {                      isvaliddate = validate(date, dateformats);                      console.writeline("the string is, {0} , date validity {1}",date, isvaliddate);                 }                 console.readline();              }               public static bool validate(string s, string[] format)             {                  datetime frdt,enudt, engdt, enidt ;                   bool fr,engu,engg, engi;                     cultureinfo[] cis = { frc,usc,gbc,inc };                     fr = datetime.tryparseexact(s, format, cis[0], datetimestyles.none, out frdt);                     engu = datetime.tryparseexact(s, format, cis[1], datetimestyles.none, out enudt);                     engg = datetime.tryparseexact(s, format, cis[2], datetimestyles.none, out engdt);                     engi = datetime.tryparseexact(s, format, cis[3], datetimestyles.none, out enidt);                      if (fr || engu || engg||engi == true)                     {                         return true;                     }                              return false;             }           } 

the first date string 10-23-2016

23 not valid month. dd-mm-yyyy fail.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -