1

我正在编写一个调用 web 服务方法的 vb.net 应用程序。有问题的 webservice 方法接受大约 20 个参数,例如 (string x, string y, string z.... Integer a, Integer b, Integer c)。

可能没有故意将任何一个整数(ab 或 c)设置为一个值。但是,因为 Integer 是一种值类型(感谢 Stack Overflow),所以我无法将其设置为 Nothing,因此当用户没有为这些整数选择特定值时,我将其默认为 -1。但是,当用户没有初始化这些整数(不是 0 或 -1,它想要 Nothing/Null)时,webservice 方法希望我将它传递给 Null/Nothing。

我如何为 web 服务提供它想要的多个条件,对 web 服务的调用略有不同(例如,如果整数 a = -1 然后用 (x,y,z,Nothing,b,c) 等调用 web 服务...... )?

4

1 回答 1

5

您可以使用Nullable(Of T)来包装值类型,以便Nothing与它们一起使用。

所以对于整数:

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

在网上搜索“可空类型 vb.net”——有很多文章解释了它们。

于 2011-10-20T20:22:22.873 回答