Hi DaTurk,
yes, passing by reference is passing an address in memory. The address of a
variable wich stores a reference to an array of byte.
Talking about reference could be misleading in C#. You could better think of
a ref and out parameter as passing a variable not a value.
So data here is a (reference type) variable, wich original belonged to the
caller.
retValue is another (reference type) variable, wich is local to this method
In the first line inside the try block you create a new array of byte and
put a reference to it in the variable retVal
After that you copy this reference to th variable data.
In the finally block you put null into the variable retVal; the variable
data is not effected by this.
"DaTurk" <mm******@hotmail.comschrieb im Newsbeitrag
news:11**********************@s48g2000cws.googlegr oups.com...
If I call this method, and pass it a byte[] by ref, and initialize
another byte array, set the original equal to it, and then null the
reference, why is the original byte array not null as well? I thought
passing by reference, your passing the address in memory.
public bool DoSomething(ref byte[] data)
{
byte[] retVal = null;
try
{
retVal = new byte[data.Length];
data = retVal;
}
catch (Exception ex)
{
}
finally
{
retVal = null;
}
}