[英]how to pass an optional parameter along with required parameters in Web methods in Vb.net?
There is a web method. 有一个网络方法。 We have 2 parameters.
我们有2个参数。 We need to pass the third parameter as optional parameter to a web service in vb.net framework 2.0 Visual studio 2005.What are the ways to give the parameter as a optional parameter?
我们需要将第三个参数作为可选参数传递给vb.net Framework 2.0 Visual Studio 2005中的Web服务。将参数作为可选参数的方式有哪些?
2 choices: 2个选择:
Always overload if you can, much clearer and simpler 如果可以的话,请始终重载,更清晰,更简单
Call a function that adds the third parameter as "" or 0 if it only has two parameters (depending if string or double or else) 调用一个将第三个参数添加为“”或0(如果它只有两个参数的话)的函数(取决于字符串,double或其他)
What I mean (or something similar, just wrote it quickly): 我的意思(或类似的东西,只是写得很快):
dim threeParameter = addThirdParameter({FirstParameter,SecondParameter[,thirdParameter]})
myWebMethod(threeParameter(0),threeParameter(1),threeParameter(2))
private function addThirdParameter(_input() as string)
dim _output(2) as string 'or double or w/e
if ubound(_input) = 1 then
_output(0) = _input(0)
_output(1) = _input(1)
'_output(2) = ""
return _output
else 'Already has 3 parameters
return _input
end if
end function
This snippet should check if you entered 2 or 3 parameters, if you entered 2, it adds an empty parameter (""), if you entered 3 it returns the input. 此代码段应检查是否输入了2个或3个参数,如果输入了2个,它将添加一个空参数(“”),如果输入了3个,则返回输入。
Hope it helps 希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.