Last post Dec 09, 2009 08:57 AM by akashenk
Dec 08, 2009 02:15 PM|akashenk|LINK
I am making use of a 3rd party dll and am encountering some strange behavior in VB, which doesn't occur in C# Perhaps someone can explain what is going on. Anyhow, I am making use of a method in this 3rd party library which accepts an array parameter ByRef.
The end result is the variable should remain null after the method call, but it is returning initialized for some reason. The following is my syntax...
Dim myVariable as Object() = Nothing
Dim str as string = DoSomething(myVariable)
I looked under the hood of the method declaration and it looks like:
Public Function DoSomething(<System.Runtime.InteropServices.OutAttribute()> ByRef Results() As Object) As String
Dim retVal As new SpecialObject
Results = retVal.Results
Partial Public Class SpecialObject
Public OverallStatus As String
Public Results() As APIObject
Public Sub New()
Me.OverallStatus="Staus Not Checked"
Public Sub New(ByVal Results() As Object)
Me.OverallStatus = "Status Checked"
Me.Results = Results
I'm not quite sure how this happens, since the array never gets initialized. Anyone have any idea?
Dec 08, 2009 06:34 PM|David Anton|LINK
There's something else going on here - when I reproduce your example 'myVariable' is set to 'Nothing'.
Dec 09, 2009 08:57 AM|akashenk|LINK
What I presented here is definitely stripped out. I'll have to dig a little deeper I guess. Thanks!