Click here to Skip to main content
15,910,130 members
Home / Discussions / C#
   

C#

 
AnswerRe: Returning date time as null [modified] Pin
0x3c03-Dec-09 5:09
0x3c03-Dec-09 5:09 
GeneralRe: Returning date time as null Pin
Joe Rozario3-Dec-09 5:15
Joe Rozario3-Dec-09 5:15 
GeneralRe: Returning date time as null Pin
0x3c03-Dec-09 5:37
0x3c03-Dec-09 5:37 
GeneralRe: Returning date time as null Pin
Joe Rozario3-Dec-09 5:41
Joe Rozario3-Dec-09 5:41 
AnswerRe: Returning date time as null Pin
PIEBALDconsult3-Dec-09 5:10
mvePIEBALDconsult3-Dec-09 5:10 
GeneralRe: Returning date time as null Pin
Joe Rozario3-Dec-09 5:18
Joe Rozario3-Dec-09 5:18 
GeneralRe: Returning date time as null Pin
PIEBALDconsult3-Dec-09 5:20
mvePIEBALDconsult3-Dec-09 5:20 
AnswerRe: Returning date time as null [modified] Pin
Luc Pattyn3-Dec-09 5:44
sitebuilderLuc Pattyn3-Dec-09 5:44 
=>Joe<= wrote:
Any idea.? suggestion?


AFAIK there are four popular ways, you've had most of them already:

1.
set aside a special value, could be Default<DateTime> or any other value you don't need as a real value. For DateTime, there is also DateTime.MaxValue

2.
nullable types, written either as Nullable<DateTime> or DateTime? (with question mark)
I don't like them much as they take more memory, and cause some trouble when parts of your environment don't know how to handle them (e.g. files, databases, ...).

3.
Use an Exception. That often is the most elegant approach, assuming the "no value" situation really is exceptional.

[ADDED, AS SUGGESTED BY PIEBALD]
4.
Return a boolean and have the value in an out parameter. Like with TryParse.
[/ADDED]

Smile | :)

Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


modified on Thursday, December 3, 2009 2:59 PM

GeneralRe: Returning date time as null Pin
Joe Rozario3-Dec-09 6:00
Joe Rozario3-Dec-09 6:00 
GeneralRe: Returning date time as null Pin
PIEBALDconsult3-Dec-09 10:45
mvePIEBALDconsult3-Dec-09 10:45 
AnswerRe: Returning date time as null Pin
souidi abderrahman3-Dec-09 5:58
souidi abderrahman3-Dec-09 5:58 
AnswerRe: Returning date time as null Pin
PIEBALDconsult3-Dec-09 8:23
mvePIEBALDconsult3-Dec-09 8:23 
GeneralRe: Returning date time as null Pin
Luc Pattyn3-Dec-09 9:02
sitebuilderLuc Pattyn3-Dec-09 9:02 
QuestionC# application to sort SQL database data and output to CSV file Pin
totally_stumped3-Dec-09 4:38
totally_stumped3-Dec-09 4:38 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
dan!sh 3-Dec-09 4:55
professional dan!sh 3-Dec-09 4:55 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
Shorgov3-Dec-09 5:13
Shorgov3-Dec-09 5:13 
AnswerRe: C# application to sort SQL database data and output to CSV file Pin
PIEBALDconsult3-Dec-09 5:15
mvePIEBALDconsult3-Dec-09 5:15 
QuestionKilling threads on form closing... Pin
Jacob Dixon3-Dec-09 2:59
Jacob Dixon3-Dec-09 2:59 
AnswerRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:12
sitebuilderLuc Pattyn3-Dec-09 3:12 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:19
Jacob Dixon3-Dec-09 3:19 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:28
sitebuilderLuc Pattyn3-Dec-09 3:28 
GeneralRe: Killing threads on form closing... Pin
Jacob Dixon3-Dec-09 3:36
Jacob Dixon3-Dec-09 3:36 
GeneralRe: Killing threads on form closing... Pin
Luc Pattyn3-Dec-09 3:58
sitebuilderLuc Pattyn3-Dec-09 3:58 
GeneralRe: Killing threads on form closing... Pin
ely_bob3-Dec-09 8:03
professionalely_bob3-Dec-09 8:03 
AnswerRe: Killing threads on form closing... Pin
Nicholas Butler3-Dec-09 3:17
sitebuilderNicholas Butler3-Dec-09 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.