Saturday, March 24, 2012

System.Nullable 2.0 Framework

The 2.0 Framework has a new type called System.Nullable. This allows
something to Not exist, basically you can pass 'Nothing' to a method whose
parameters as System.Nullable.

Im looking at table adapters ; you know those clever little things which
allow you to contrsuct methods for manipulating data use this. So a method
might be declared someting like this.

Private Sub myMethod(ByVal myYear As System.Nullable(Of Integer), ByVal
myweek As System.Nullable(Of Integer))

End Sub

My question is. How to I translate this into a practical method call for a
value which may or may not exits. Lets say we have two text boxes.
yearTextBox and weekTextBox.

How to I assign an integer value or nothing depending on if the box is
emtpy, because you cant assign nothing to an integer. I dont want multiple
call lines to the one method, just one.

--
Goofy

--
GoofyGot it

Dim year As System.Nullable(Of Single)

Dim week As System.Nullable(Of Integer)

"Goofy" <me@.mine.comwrote in message
news:%23X%23OA%23DJHHA.320@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

The 2.0 Framework has a new type called System.Nullable. This allows
something to Not exist, basically you can pass 'Nothing' to a method whose
parameters as System.Nullable.
>
Im looking at table adapters ; you know those clever little things which
allow you to contrsuct methods for manipulating data use this. So a method
might be declared someting like this.
>
Private Sub myMethod(ByVal myYear As System.Nullable(Of Integer), ByVal
myweek As System.Nullable(Of Integer))
>
End Sub
>
My question is. How to I translate this into a practical method call for a
value which may or may not exits. Lets say we have two text boxes.
yearTextBox and weekTextBox.
>
How to I assign an integer value or nothing depending on if the box is
emtpy, because you cant assign nothing to an integer. I dont want multiple
call lines to the one method, just one.
>
--
Goofy
>
>
>
--
Goofy
>


"Goofy" <me@.mine.comwrote in message
news:uMXc8jEJHHA.3872@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

Got it
>
Dim year As System.Nullable(Of Single)
>
Dim week As System.Nullable(Of Integer)


Not sure about VB.NET, but in C# v2 you can do this simply by appending a
question mark to the datatype e.g.

Int32 intYear = 0; // not nullable
Int32? intYear = null; // nullable
Didnt know that, but then I dont code in C# normally. This nullable facility
is really usefull in some situations I find.

"Mark Rae" <mark@.markNOSPAMrae.comwrote in message
news:utmozHFJHHA.536@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

"Goofy" <me@.mine.comwrote in message
news:uMXc8jEJHHA.3872@.TK2MSFTNGP06.phx.gbl...
>

Quote:

Originally Posted by

>Got it
>>
>Dim year As System.Nullable(Of Single)
>>
>Dim week As System.Nullable(Of Integer)


>
Not sure about VB.NET, but in C# v2 you can do this simply by appending a
question mark to the datatype e.g.
>
Int32 intYear = 0; // not nullable
Int32? intYear = null; // nullable
>


"Goofy" <me@.mine.comwrote in message
news:%23r$GlYOJHHA.3264@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Didnt know that, but then I dont code in C# normally.


Conversely, I never go anywhere near VB.NET... :-)

Quote:

Originally Posted by

This nullable facility is really usefull in some situations I find.


I couldn't agree more! One of the most important enhancements in v2, along
with generics.

0 comments:

Post a Comment