Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# nullable date
Message
From
25/01/2011 12:50:29
 
 
To
25/01/2011 11:11:56
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01497353
Message ID:
01497376
Views:
42
Thanks 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
>>>
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform