By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

is a byte array Byte[] pass by reference

P: n/a
In the default state

ie

somemethod(Byte [] array);

is the byte array passed by method or by reference ? or do you have to
use the ref keyword to be able to mod the contents of the orig array
from inside the method ?

thanks

peted
May 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I think u have to use ref keyword.
May 11 '07 #2

P: n/a
"Peted" wrote in message news:le********************************@4ax.com...
somemethod(Byte [] array);

is the byte array passed by method or by reference ? or do you have to
use the ref keyword to be able to mod the contents of the orig array
from inside the method ?
Without using "ref", if you modify array[i] inside somemethod, the
corresponding position is modified in the original array. If you use a "ref"
keyword, then you would be passing "a reference to the reference", which
would allow you to point the received reference somewhere else (moving the
array to a different array), besides allowing you to merely modify the
contents.
May 11 '07 #3

P: n/a
On May 11, 9:50 am, Peted wrote:
In the default state

ie

somemethod(Byte [] array);

is the byte array passed by method or by reference ?
The *reference* to the byte array is passed by value.
or do you have to use the ref keyword to be able to mod the
contents of the orig array from inside the method ?
You can change the *contents* of the array just by passing the
reference by value.
If you want the method to be able to change it to a completely
different array (e.g. a different size) you'll need to pass the
parameter by reference.

See http://pobox.com/~skeet/csharp/parameters.html

Jon

May 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.