OK, this is the one that did it for me. i understand the error of my
thinking. I was remembering what i read in the help system:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 FEB.1033/csref/html/vclrfPassingMet hodParameters.h tm#vclrfpassing methodparameter s_referencetype s
Passing Reference-Type Parameters
A variable of a reference type does not contain its data directly; it
contains a reference to its data. When you pass a reference-type parameter
by value, it is possible to change the data pointed to by the reference,
such as the value of a class member. However, you cannot change the value of
the reference itself; that is, you cannot use the same reference to allocate
memory for a new class and have it persist outside the block. To do that,
pass the parameter using the ref (or out) keyword. For simplicity, the
following examples use ref.
Example 4: Passing Reference Types by Value
The following example demonstrates passing a reference-type parameter,
myArray, by value, to a method, Change. Because the parameter is a reference
to myArray, it is possible to change the values of the array elements.
However, the attempt to reassign the parameter to a different memory
location only works inside the method and does not affect the original
variable, myArray.
....
So my original assumption was correct, but as you pointed out, i
instantiated my object to null, so the reference i sent was null and you
cannot do anything with a null reference. If i first instantiate the object
and then pass it by value, changing the object in the method has an effect
on the object.
Thanks for clearing the fog on that one!
TS
"KWienhold" <he******@trash mail.netwrote in message
news:11******** *************@k 70g2000cwa.goog legroups.com...
More precisely speaking, a reference object is basically a pointer to
the memory location that holds the actual data. When you pass a
reference object by value to a function this pointer is copied to a new
pointer instance that will only be valid inside the function.
Normally this doesn't make much of a difference to passing it by
reference, since you will still be making changes to the same data in
memory, only through two different pointers (the original one if passed
by ref, the copy if passed by value).
When you pass a null reference by value, the pointer points to no data
yet, so when it is copied you receive a new null pointer. Initializing
this pointer won't change the fact that your original pointer still
points to nothing, that's why your object is still null after the
function returns.
If you initialize your object with a new instance first, pass that to
the function and alter its properties, you should see the changes you
are looking for, although the same can be achieved by simply passing it
as a reference.
Sincerely,
Kevin Wienhold
Cor Ligthert [MVP] schrieb:
>TS,
In my idea are you writing it yourself. (In slightly other words bellow)
You are passing a reference to "zero objects" to a method, and when you
are
changing things in your method those "zero objects" will not be changes.
If you want to sent a to be used reference than you have to send that
reference and not the "zero objects".
Cor
"TS" <ma**********@n ospam.nospamsch reef in bericht
news:uM******* *******@TK2MSFT NGP02.phx.gbl.. .
>I was under the assumption that if you pass an object as a param to a
method and inside that method this object is changed, the object will
stay
changed when returned from the method because the object is a reference
type?
my code is not proving that. I have a web project i created from a web
service that is my object:
public class ExcelService : SoapHttpClientP rotocol
{
public ExcelService(); ...
In my code in initialize the object varialbe to null and then pass it
to a
method that instantiates it, but when the method returns the varaible
is
still null
ExcelService es = null;
string sessionId = OpenSession(es) ;
es equals null here!!!!!
thanks