It is actually easy to define a Nullable type in VB just do:
Dim aVariable As Nullable(Of Integer)
And there you go, aVariable can now be set to Nothing (null) quite happily.
Problem: Nullable(Of T) is a Structure not a Class so you can't use it for optional parameters (not that those exist in c# anyway) and you can't test IsNothing on it you have to do .HasValue instead.
I need a type that...
User Profile
Collapse
-
Thanks for the suggestions,
I had considered the "special values" solution, but it feels like a kludge. You never know, one day date.MinValue might be a valid parameter value!
After much casting about I found a sort of solution (not as elegant as I had hoped but does the job) using generics.
I define a generic type that can accept Nothing even for simple intrinsic types (like integer) and then...Leave a comment:
-
How to specify DEFAULT for optional parameter to stored procedure wrapper function
My problem is this (apologies if this is a little long ... hang in there):
I can define a function in VB.NET with optional parameters that wraps a SQL procedure:
Code:Sub Test(Optional ByVal Arg1 As Integer = 0, _ Optional ByVal Arg2 As Integer = 0, _ Optional ByVal Arg3 As Integer = 0) ' Call my SQL proc with the same signature End Sub
Last edited by tlhintoq; Sep 18 '09, 07:09 PM. Reason: [CODE] ...your code goes here... [/CODE] tags added
No activity results to display
Show More
Leave a comment: