문제

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...)?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top