System.Nullable 2.0 Framework

G

Goofy

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.
 
G

Goofy

Got it

Dim year As System.Nullable(Of Single)

Dim week As System.Nullable(Of Integer)
 
M

Mark Rae

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
 
G

Goofy

Didnt know that, but then I dont code in C# normally. This nullable facility
is really usefull in some situations I find.
 
M

Mark Rae

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

Conversely, I never go anywhere near VB.NET... :)
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top