Re: Return ByRef
- From: "Torsten Kerz" <tkerz@xxxxxxxxxx>
- Date: Wed, 20 Dec 2006 14:43:23 +0100
Hi Samuel.
Public A as SqlException 'Global varibale
Public Function Method as SqlException
Return A
End Function
Public sub Method2 (ByRef ob as SqlException)
Try
Throw new SqlException
Catch Ex AS SQL
ob=Ex
End Sub
Sub Main()
Method2(Method1)
'At this point A = nothing if though a value was assigned to it in
method2
End Sub
Yes ... it is nothing and it must be nothing.
At the point "Method2(Method1)" you give a result of a method into another
method. This is a expression and not a variable, so the value can't be given
by reference.
Try this instead and all should do fine:
a = method1
Method2(a)
"Jay B. Harlow" <Jay_Harlow_MVP@xxxxxxxxxxxxx> wrote in message
news:%238bSDR8IHHA.816@xxxxxxxxxxxxxxxxxxxxxxx
Samuel,
Can you better describe what you are attempting?
It almost sounds like you are thinking C++ or you are simply confusing
reference types with ByRef parameters.
Within .NET: The Class keyword defines a Reference type, this means that
the object exists on the heap: return values, fields, variables &
parameters refer (reference) to this object on the heap.
While the "Structure" keyword defines a Value type. This means that the
"object" (value really) exists "in-line" locally either on the stack in
the case of return values, variables & parameters or inside a larger
object on the heap. Boxed value types are special in that the value
exists as an object on the heap.
Return values will simply return the value of a Value type (Structure) or
the reference to the object on the heap of a Reference Type (Class,
Interface, Delegate).
Again can you better describe what you are attempting, or at the very
least include pseudo code on what you are expecting.
Call a method that returns an objectPublic Function Something() As Object
End Function
Use that call as an argument to a ByRef parameter thenPublic Sub SomethingElse(ByRef value As Object)
End Sub
SomethingElse(Something())
on the return I want to access that Object directly that has a globalHuh? that object was passed to the SomethingElse method, you didn't
scope
assign it to "global scope" anything...
--
Hope this helps
Jay B. Harlow
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Samuel Shulman" <samuel.shulman@xxxxxxxxxxxx> wrote in message
news:uJQTMv6IHHA.1816@xxxxxxxxxxxxxxxxxxxxxxx
Hi
I wander there is a way to return ByRef just like passing ByRef
What I want to achieve is the following:
Call a method that returns an object
Use that call as an argument to a ByRef parameter then on the return I
want to access that Object directly that has a global scope
Currently the Original Object doesn't seem to pass and therefore it has
no value
Thank you,
Sam
.
- Follow-Ups:
- Re: Return ByRef
- From: Samuel Shulman
- Re: Return ByRef
- References:
- Return ByRef
- From: Samuel Shulman
- Re: Return ByRef
- From: Jay B. Harlow
- Re: Return ByRef
- From: Samuel Shulman
- Return ByRef
- Prev by Date: Re: Sound recording - HELP!
- Next by Date: Re: Threading
- Previous by thread: Re: Return ByRef
- Next by thread: Re: Return ByRef
- Index(es):
Relevant Pages
|