有人见过这个吗?
Public Shared Function IsAvailableByCampaignId(ByVal cn As SqlConnection, ByVal tr As SqlTransaction, ByVal campaignId As Integer, ByRef dest As PricingThresholds) As Boolean
Dim retObj = ItemTypes.PricingThresholds.GetThresholds(cn, tr, campaignId)
If retObj IsNot Nothing Then
dest = New PricingThresholds(retObj)
End If
Dim retVal As Boolean = retObj IsNot Nothing
Return retVal
End Function当我呼唤内心的时候
Dim retObj = ItemTypes.PricingThresholds.GetThresholds(cn, tr, campaignId)
我得到了一个非空或者什么都没有的retObj,但是我用它来构建一个新的PricingThresholds,它是我需要返回的正确类型,并且我成功地创建了一个有效的返回类型对象,但是我从外部调用返回了参数,传递的ByRef没有值,并且为nothing或null。
这就像VB不能工作一样。
我想我可以用另一种方式返回它。
发布于 2013-07-29 02:26:14
下面的代码显示一切正常,即dest正在被重新赋值,并在IsAvailableByCampaignId函数之外保留它的值:
Sub Main()
Dim dest As New PricingThresholds(1)
Dim p = IsAvailableByCampaignId(dest)
End Sub
Class PricingThresholds
Dim _id As Integer
Sub New(id As Integer)
_id = id
End Sub
End Class
Public Function IsAvailableByCampaignId(ByRef dest As PricingThresholds) As Boolean
dest = New PricingThresholds(2)
Return True
End Function请随意使用这段代码,看看是否可以重现您所拥有的bevahior。
https://stackoverflow.com/questions/17911021
复制相似问题