it works in VB 2005 (dotnet 2.0) but it's ugly.
You can't use it like a normal variable, I thought it might work like an Object type but it doesn't.
Rather than this:
dim oInt as object
dim i as integer
if oInt is nothing then
msgbox("int is null")
else
i = cint(oInt)
end if
you have this.
Dim oInt as nullable(of integer)
dim i as integer
if oInt.HasValue = false then
msgbox("int is null")
else
i = oInt.Value
end if
The problem here is that if your variable is null and you happen to invoke the Value property it barfs up an unhandled exception.
so for instance, my favorite one is this.
AddParamToSQLCmd(sqlCmd, "@SomeID", SqlDbType.Int, 0, ParameterDirection.Input, iif(oInt.HasValue, oInt.Value, DBNull.value))
Will result in an runtime error when your Supposed Nullable value is null!!!
so here's nullable(of integer) vs Object code
nullable(of integer)
if oInt.HasValue then
AddParamToSQLCmd(sqlCmd, "@SomeID", SqlDbType.Int, 0, ParameterDirection.Input, oInt.Value)
else
AddParamToSQLCmd(sqlCmd, "@SomeID", SqlDbType.Int, 0, ParameterDirection.Input, dbnull.value)
end if
Object
AddParamToSQLCmd(sqlCmd, "@SomeID", SqlDbType.Int, 0, ParameterDirection.Input, oInt)