Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# nullable date
Message
De
25/01/2011 12:53:20
 
 
À
25/01/2011 12:50:29
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01497353
Message ID:
01497377
Vues:
40
>Thanks Bonnie

You're welcome! =0)

~~Bonnie



>
>>>I had just removed the nullable parameter and changed the call to this:
>>>
>>>
            if (this.Entity.IssueDate != null)
>>>            {
>>>                 int policyYear = CalculateAge((DateTime)this.Entity.IssueDate, DateTime.Now); // need to check if terminated
>>>            }
>>>
>>>
>>>That seems to work. But is it better to do it the way you suggested?

>>
>>I typically prefer to keep as much functionality in a method as possible. If one needs to check for the existence or nullability of an object before some action can be performed on it, I think it's better to do it all in one place, in the method itself. That said, I guess it also depends on how you plan to be calling this method. IOW, if you need this functionality with both nullable dates and regular dates, then you could do what you've done above, or you could have two overloaded methods, one that accepts the nullable type and one that doesn't.
>>
>>~~Bonnie
>>
>>
>>
>>
>>>
>>>>When using Nullable types, you have to use the .Value property.
>>>>
>>>>
>>>>if (StartDate.HasValue())
>>>>    StartDate.Value.Year ...etc.etc.
>>>>
>>>>
>>>>~~Bonnie
>>>>
Bonnie Berent DeWitt
NET/C# MVP since 2003

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

Click here to load this message in the networking platform