Click here to Skip to main content
15,887,683 members
Home / Discussions / C#
   

C#

 
AnswerRe: What is this line? PinPopular
V.14-Jun-11 20:30
professionalV.14-Jun-11 20:30 
AnswerRe: What is this line? Pin
Roger Wright14-Jun-11 20:32
professionalRoger Wright14-Jun-11 20:32 
GeneralRe: What is this line? Pin
Łukasz Nowakowski14-Jun-11 21:07
Łukasz Nowakowski14-Jun-11 21:07 
GeneralRe: What is this line? Pin
Pete O'Hanlon14-Jun-11 21:17
mvePete O'Hanlon14-Jun-11 21:17 
GeneralRe: What is this line? Pin
Łukasz Nowakowski14-Jun-11 21:23
Łukasz Nowakowski14-Jun-11 21:23 
GeneralRe: What is this line? Pin
Roger Wright14-Jun-11 21:25
professionalRoger Wright14-Jun-11 21:25 
GeneralRe: What is this line? Pin
RobCroll14-Jun-11 22:56
RobCroll14-Jun-11 22:56 
GeneralRe: What is this line? Pin
BobJanova15-Jun-11 0:41
BobJanova15-Jun-11 0:41 
To expand on the last reply, it is useful when a variable can validly take the whole range of the type in question, and can also have a 'not set' value. Typically we have either used an invalid value (e.g. testing getchar() for -1 in old school C; -1 is a common 'not set' value in ints still) or created another boolean variable to define whether or not we set a value:
bool customerLikedProduct;
bool customerResponded;


People have also solved that one with a three way enum ...
enum NullableBool { True, False, Maybe }

... but when you do that you lose the ability to use boolean logical operators, compatibility with external data sources or applications, etc.

In these cases, you would like to be able to represent the 'not set' value within one variable. That's what nullable types give you:
bool? customerLikedProduct;


As already mentioned, it's particularly useful for working with databases where null values are a common and standard thing.

For me, using -1 or double.NaN is fine, as long as that can never be a valid value for the variable in question. But there are times when the whole valid range for the natural data type is valid and you should use nullable types.
GeneralHow can I add application configuration file in C# project? Pin
bulbul01198914-Jun-11 18:48
bulbul01198914-Jun-11 18:48 
GeneralRe: How can I add application configuration file in C# project? Pin
Roger Wright14-Jun-11 19:54
professionalRoger Wright14-Jun-11 19:54 
QuestionMessage Removed Pin
14-Jun-11 18:38
nehajain1214-Jun-11 18:38 
AnswerRe: Dwnload file in c# Pin
walterhevedeich14-Jun-11 19:02
professionalwalterhevedeich14-Jun-11 19:02 
GeneralRe: Dwnload file in c# Pin
Richard MacCutchan16-Jun-11 3:43
mveRichard MacCutchan16-Jun-11 3:43 
AnswerRe: Dwnload file in c# Pin
Ravi Sant20-Jun-11 1:25
Ravi Sant20-Jun-11 1:25 
QuestionDeny access to a datatable while in use from another object Pin
MAW3014-Jun-11 18:10
MAW3014-Jun-11 18:10 
AnswerRe: Deny access to a datatable while in use from another object Pin
Richard Andrew x6414-Jun-11 20:12
professionalRichard Andrew x6414-Jun-11 20:12 
AnswerRe: Deny access to a datatable while in use from another object Pin
jschell15-Jun-11 9:04
jschell15-Jun-11 9:04 
QuestionParsing HTML of some website using C Sharp. Pin
shivamkalra14-Jun-11 15:35
shivamkalra14-Jun-11 15:35 
AnswerRe: Parsing HTML of some website using C Sharp. Pin
JV999914-Jun-11 21:55
professionalJV999914-Jun-11 21:55 
AnswerRe: Parsing HTML of some website using C Sharp. Pin
BobJanova15-Jun-11 0:29
BobJanova15-Jun-11 0:29 
AnswerRe: Parsing HTML of some website using C Sharp. Pin
GenJerDan15-Jun-11 3:59
GenJerDan15-Jun-11 3:59 
QuestionCall Web Service Without Reference? Pin
Kevin Marois14-Jun-11 12:02
professionalKevin Marois14-Jun-11 12:02 
AnswerRe: Call Web Service Without Reference? Pin
Kevin Marois14-Jun-11 13:13
professionalKevin Marois14-Jun-11 13:13 
AnswerRe: Call Web Service Without Reference? Pin
PIEBALDconsult14-Jun-11 14:11
mvePIEBALDconsult14-Jun-11 14:11 
QuestionHow to learn Web Based Apps? Pin
Software200714-Jun-11 5:44
Software200714-Jun-11 5:44 

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.