[RESOLVED] Variable Declaration Question
May I ask exactly what this means: bool? bSendEmail ?
I was getting an error from the compiler complaining of my use of an unassigned local variable if I just declared it as bool bSendEmail. I could not find where it wasn't being assigned. I was not sure if I wanted to initialize it to true or to false. The above made the compiler happy, but confused me.
Thanks.
Re: Variable Declaration Question
bool? means it's a nullable boolean... as opposed to bool which isn't nullable.
In VB it would be
Dim ridesBusToWork3 As Nullable(Of Boolean)
More info -
C# - http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx
VB - http://msdn.microsoft.com/en-us/library/ms235245.aspx
-tg
Re: Variable Declaration Question
Cool (and thanks for the quick reply).
So the compiler has intialized it to null for me, and that is why it doesn't complain anymore that it's unassigned?
A Nullable<bool> can be assigned the values true false, or null
Re: Variable Declaration Question
yup... because now null becomes a valid "value" for it.
-tg
Re: [RESOLVED] Variable Declaration Question
A sidenote - in VB you can also use the '?' syntax:
Dim b As Boolean?
or
Dim b? As Boolean
or
Dim b As Nullable(Of Boolean)