Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
New System.DateTime()
Message
De
19/01/2006 00:38:21
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01088229
Message ID:
01088274
Vues:
9
My only comment on this method of doing this is that, as I've said before, exceptions are expensive and should really not be used for the purpose of validating stuff. I suppose that if, for the most part, you'll only be getting valid data, then the exception will rarely be caught and you'll probably not get that hit all that much.

You decide. <g>

~~Bonnie




>I am given a byte value for month and a byte value for day. I want to verify that this is a correct date and instead of writing a lot of code to do this I figured I would just pass it to the DateTime constructor with the year equal to 2004 (because it was a leap year). So I do something like this:
>
>byte month = 0x01;
>byte day = 0x01;
>try
>{
>  new System.DateTime(2004, month, day);
>}
>catch (Exception ex)
>{
>  MessageBox.Show(ex.ToString(), "Month and/or day not valid");
>}
>
>
>I do not need the DateTime object so I do not assign a variable. Is this bad?
>
>Should I instead use the following code?
>
>byte month = 0x01;
>byte day = 0x01;
>try
>{
>  System.DateTime dt = new System.DateTime(2004, month, day);
>}
>catch (Exception ex)
>{
>  MessageBox.Show(ex.ToString(), "Month and/or day not valid");
>}
>
>
>Or doesn't it matter (estetics aside<s>)?
>
>If someone answers I will explain why I am wondering about such a trivial thing :)
>
>Einar
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform