Question

I am writing a vb.net application which calls a webservice method. The webservice method in question accept some 20 parameters, such as (string x, string y, string z.... Integer a, Integer b, Integer c).

Its possible that any one of the integers (a b or c) is not purposefully set to a value. However, because Integer is a value type (thank you Stack Overflow) I cant set it to Nothing, thus I default it to -1 when the user has not selected a specific value for those integers. However, the webservice method wants me to pass it Null/Nothing when the user did not initialize those integers (not 0, or -1, it wants Nothing/Null).

How do I give the webservice what it wants short of multiple conditionals, with slightly different calls to the webservice (e.g. if integer a = -1 then call webservice with (x,y,z,Nothing,b,c) etc...)?

Was it helpful?

Solution

You can use Nullable(Of T) to wrap value types so you can use Nothing with them.

So for integers:

Dim nullInt As Nullable(Of Integer)
nullInt = 10
nullInt = Nothing

Search the web for "nullable types vb.net" - there are many articles that explain them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top