VB .NET中的输出参数? [英] Output Parameters in VB .NET ?
问题描述
我正在构建一个Web服务并试图获得类似于
的输出:
<?xml version =" 1.0 " encoding =" utf-8"?>
< soap:Envelope xmlns:soap =" http://schemas.xmlsoap.org/soap/envelope/">
< soap:Body>
< Add2Response>
< Add2Result> 3< / Add2Result>
< ; sum> 3< / sum>
< / Add2Response>
< / soap:Body>
< / soap:Envelope> ;
C#语言允许这样的函数:
public int Add2(int x,int y,out int sum)
{
sum = x + y;
返还金额;
}
在VB函数/子程序中是否允许输出参数?如果是这样,
请提供一个例子。如果有任何其他方式返回
多个输出变量,请告诉我。
谢谢
------------------------------------------------ -----
生命之风吹向我们每个人。
你的帆是否朝着正确的方向前进?
http://www.icreateMyLife.com
I''m building a web service and trying to get an output similar to
this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Add2Response>
<Add2Result>3</Add2Result>
<sum>3</sum>
</Add2Response>
</soap:Body>
</soap:Envelope>
The C# language allows a function like this:
public int Add2(int x, int y, out int sum)
{
sum = x + y;
return sum;
}
Aren''t output parameters allowed in VB functions/subroutines? If so,
please provide an example. If there is any other way to return
multiple output variables, please let me know that too.
Thanks
-----------------------------------------------------
The winds of life blow on each of us.
Is your sail set in the right direction?
http://www.ICreateMyLife.com
推荐答案
为参数指定ByRef而不是ByVal。
公共函数Add2(ByVal x As Integer,ByVal y As Integer,ByRef sum As
整数)作为整数
ByRef作为ref工作C#中的参数,但就像out一样,并不需要
预分配。
当然,这个例子有点奇怪,因为out参数和
函数的返回值是相同的。
-Rob Teixeira [MVP]
" ; Juan Sutton < JC ****** @ usa.com>在消息中写道
news:23 ************************** @ posting.google.c om ...
specify ByRef instead of ByVal for the parameter.
Public Function Add2(ByVal x As Integer, ByVal y As Integer, ByRef sum As
Integer) As Integer
ByRef works as "ref" paramaters in C#, but just like "out", doesn''t require
pre-assignment.
Of course, this example is a bit strange, since the out parameter AND the
function return value are the same thing.
-Rob Teixeira [MVP]
"Juan Sutton" <jc******@usa.com> wrote in message
news:23**************************@posting.google.c om...
C#语言允许这样的函数:
public int Add2(int x,int y,out int sum)
{
sum = x + y;
返回总和;
在VB函数/子程序中不允许输出参数?如果是这样,请提供一个例子。如果还有其他方法可以返回多个输出变量,请让我知道。
谢谢
---------- -------------------------------------------
风的生活在我们每个人身上。
你的帆是否朝着正确的方向前进?
http://www.ICreateMyLife.com
非常感谢。这么简单的解决方案。
虽然有一个问题。这需要SOAP请求
包括ByRef参数。我无法控制客户
的行为,所以这可能是一个问题。
任何其他想法都表示赞赏。
----------------------------------------------- ------
生命之风吹向我们每个人。
你的风帆是否朝着正确的方向发展?
http://www.icreateMyLife.com
" Rob Teixeira [MVP] QUOT; < RobTeixeira @@ msn.com>在消息新闻中写道:< #e ************** @ TK2MSFTNGP11.phx.gbl> ...
Thank you very much. Such a simple solution.
Although, there is one gotcha. That requires the soap request to
include the ByRef parameter. I have no control over the client
behavior so this may be a problem.
Any other ideas are appreciated.
-----------------------------------------------------
The winds of life blow on each of us.
Is your sail set in the right direction?
http://www.ICreateMyLife.com
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message news:<#e**************@TK2MSFTNGP11.phx.gbl>...
为参数指定ByRef而不是ByVal。
公共函数Add2(ByVal x As Integer,ByVal y As Integer,ByRef sum As
Integer)As Integer
ByRef作为ref工作C#中的参数,但就像out一样,不需要
预分配。
当然,这个例子有点奇怪,因为out参数和<功能返回值是一回事。
-Rob Teixeira [MVP]
" Juan Sutton" < JC ****** @ usa.com>在消息中写道
新闻:23 ************************** @ posting.google.c om ...
specify ByRef instead of ByVal for the parameter.
Public Function Add2(ByVal x As Integer, ByVal y As Integer, ByRef sum As
Integer) As Integer
ByRef works as "ref" paramaters in C#, but just like "out", doesn''t require
pre-assignment.
Of course, this example is a bit strange, since the out parameter AND the
function return value are the same thing.
-Rob Teixeira [MVP]
"Juan Sutton" <jc******@usa.com> wrote in message
news:23**************************@posting.google.c om...
C#语言允许这样的函数:
public int Add2(int x,int y,out int sum)
{
sum = x + y;
返回总和;
在VB函数/子程序中不允许输出参数?如果是这样,请提供一个例子。如果还有其他方法可以返回多个输出变量,请让我知道。
谢谢
---------- -------------------------------------------
风的生活在我们每个人身上。
你的帆是否朝着正确的方向前进?
http://www.ICreateMyLife.com
Juan,
您是否考虑过创建返回带有
值的对象而不是带副作用的函数的函数?
在使用P / Invoke时,可以使用OutAttribute来仅仅输出
参数作为输出,我认为Web
方法有类似的东西,但我现在没有找到任何链接。
希望这有帮助
Jay
" Juan Sutton" < JC ****** @ usa.com>在消息中写道
news:23 ************************** @ posting.google.c om ...
Juan,
Have you considered creating a function that returns an object with both
values instead of a function with side effects?
In you are using P/Invoke you can use the OutAttribute to signal the
parameter as output only, I thought there was something similar for Web
methods, however I''m not finding any links right now.
Hope this helps
Jay
"Juan Sutton" <jc******@usa.com> wrote in message
news:23**************************@posting.google.c om...
非常感谢。这么简单的解决方案。
虽然有一个问题。这需要soap请求包含ByRef参数。我无法控制客户的行为,所以这可能是一个问题。
任何其他想法都表示赞赏。
--------- --------------------------------------------
风我们每个人的生活都会受到打击。
你的风帆是否朝着正确的方向发展?
http://www.ICreateMyLife.com
Rob Teixeira [MVP]" < RobTeixeira @@ msn.com>在消息中写道
Thank you very much. Such a simple solution.
Although, there is one gotcha. That requires the soap request to
include the ByRef parameter. I have no control over the client
behavior so this may be a problem.
Any other ideas are appreciated.
-----------------------------------------------------
The winds of life blow on each of us.
Is your sail set in the right direction?
http://www.ICreateMyLife.com
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:< #e ************** @ TK2MSFTNGP11.phx.gbl> ...
news:<#e**************@TK2MSFTNGP11.phx.gbl>...
为参数指定ByRef而不是ByVal。
公共函数Add2(ByVal x As Integer,ByVal y As Integer,ByRef sum
As Integer )作为整数
ByRef作为ref工作C#中的参数,但就像out一样,不需要
需要预先分配。
当然,这个例子有点奇怪,因为out参数AND
函数返回值是一回事。
-Rob Teixeira [MVP]
" Juan Sutton" < JC ****** @ usa.com>在消息中写道
新闻:23 ************************** @ posting.google.c om ...
specify ByRef instead of ByVal for the parameter.
Public Function Add2(ByVal x As Integer, ByVal y As Integer, ByRef sum As Integer) As Integer
ByRef works as "ref" paramaters in C#, but just like "out", doesn''t require pre-assignment.
Of course, this example is a bit strange, since the out parameter AND the function return value are the same thing.
-Rob Teixeira [MVP]
"Juan Sutton" <jc******@usa.com> wrote in message
news:23**************************@posting.google.c om...
C#语言允许这样的函数:
public int Add2(int x,int y,out int sum)
{
sum = x + y;
返回总和;
在VB函数/子程序中不允许输出参数?如果是这样,请提供一个例子。如果还有其他方法可以返回多个输出变量,请让我知道。
谢谢
---------- -------------------------------------------
风的生活在我们每个人身上。
你的帆是否朝着正确的方向前进?
http://www.ICreateMyLife.com
这篇关于VB .NET中的输出参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!