首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

参数该怎么传递呢

2012-02-15 
参数该如何传递呢Private Shared Function ModifyPerson(ByVal reqbuffer() As Byte) As Byte()Dim reques

参数该如何传递呢
Private Shared Function ModifyPerson(ByVal reqbuffer() As Byte) As Byte()

Dim request As New IB1001Request(reqbuffer)
Dim resp As New IB1001Response()

Dim retBufferRequest() As Byte = Array.CreateInstance(GetType(Byte), request.length)
Array.Copy(request.buffer, retBufferRequest, request.length)
....

ExistMPPS(reqbuffer, IS_CP, IS_AM, IS_IB, IS_MPPSClient)
.....
End Function

Public Shared Sub ExistMPPS(ByVal reqBuffer() As Byte, ByRef IS_CP As Boolean, ByRef IS_AM As Boolean, ByRef IS_IB As Boolean, ByRef IS_MPPSClient As Boolean)
.....

  Dim request As New IB1001Request(reqBuffer)
  Dim resp As New IB1001Response()

End Sub

以上的写法是可以的,但我想将 request 在ExistMPPS过程中作参数传递可以吗,该如何写呢,谢谢!

我尝试用

Public Shared Sub ExistMPPS(ByVal request As IB1001Request, ByRef IS_CP As Boolean, ByRef IS_AM As Boolean, ByRef IS_IB As Boolean, ByRef IS_MPPSClient As Boolean)

但不成,请问是何原因呢

[解决办法]
因为ByVal是按值传递,如果在方法内New的话,只是将方法内定义的局部变量request指向新的地址而已,并不影响调用方。

所以应该用ByRef
[解决办法]
我尝试用 

Public Shared Sub ExistMPPS(ByVal request As IB1001Request, ByRef IS_CP As Boolean, ByRef IS_AM As Boolean, ByRef IS_IB As Boolean, ByRef IS_MPPSClient As Boolean) 

但不成,请问是何原因呢

==========
怎么不成?报什么错误?
把ByVal request As IB1001Request 改成ByVal request As object这样。
然后在用到request的地方用ctype (request,IB1001Request)试试看

热点排行