DaveHope
Jan 21st, 2006, 04:36 PM
Hello all,
First post. So I'll try and make it a good one :)
I started with C# earlier today having dabbled with VB4, ANSI C, C++, PHP, Java etc etc. I've got a string which I'm trying to parse as a date using DateTime.Prase ( I know, I should Use DateTime.ParseExact., but I'd just like to get it working before improving my code :P).
I'm storing two dates is a text file, encrypted using System.Security.Cryptography (Wow! - How cool is that? .Net makes it soo easy :)), these dates are then being decrypted and compared. Basically, DateTime doesn't like one of them as a date, as you can see below:
Decrypted key:21/01/2006 22:28:02|21/01/2007 22:28:02
Unhandled Exception: System.FormatException: String was not recognized as a valid DateTime.
in <0x00121> System.DateTime:Parse (System.String s, IFormatProvider fp, DateTimeStyles styles)
in <0x0002c> System.DateTime:Parse (System.String s, IFormatProvider fp)
in <0x00022> System.DateTime:Parse (System.String s)
in <0x00076> LicenseKey:get_ValidFrom ()
in <0x000a6> ProductRegistration:Main (System.String[] args)
And, here's the important bit of code which gets the first date:
public DateTime ValidFrom
{
get
{
string KeyData = this.Decode(this.Raw);
string[] KeyArray;
KeyArray = System.Text.RegularExpressions.Regex.Split(KeyData, "\\|");
return DateTime.Parse( KeyArray[0] );
}
}
There's then an identical function below which gets the second date. When I try and access these, well, as you've already seen. It doesn't work. Any ideas ? :)
First post. So I'll try and make it a good one :)
I started with C# earlier today having dabbled with VB4, ANSI C, C++, PHP, Java etc etc. I've got a string which I'm trying to parse as a date using DateTime.Prase ( I know, I should Use DateTime.ParseExact., but I'd just like to get it working before improving my code :P).
I'm storing two dates is a text file, encrypted using System.Security.Cryptography (Wow! - How cool is that? .Net makes it soo easy :)), these dates are then being decrypted and compared. Basically, DateTime doesn't like one of them as a date, as you can see below:
Decrypted key:21/01/2006 22:28:02|21/01/2007 22:28:02
Unhandled Exception: System.FormatException: String was not recognized as a valid DateTime.
in <0x00121> System.DateTime:Parse (System.String s, IFormatProvider fp, DateTimeStyles styles)
in <0x0002c> System.DateTime:Parse (System.String s, IFormatProvider fp)
in <0x00022> System.DateTime:Parse (System.String s)
in <0x00076> LicenseKey:get_ValidFrom ()
in <0x000a6> ProductRegistration:Main (System.String[] args)
And, here's the important bit of code which gets the first date:
public DateTime ValidFrom
{
get
{
string KeyData = this.Decode(this.Raw);
string[] KeyArray;
KeyArray = System.Text.RegularExpressions.Regex.Split(KeyData, "\\|");
return DateTime.Parse( KeyArray[0] );
}
}
There's then an identical function below which gets the second date. When I try and access these, well, as you've already seen. It doesn't work. Any ideas ? :)