PC Review


Reply
Thread Tools Rate Thread

is a byte array Byte[] pass by reference

 
 
Peted
Guest
Posts: n/a
 
      11th May 2007
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
 
Reply With Quote
 
 
 
 
MarcuEusebiu@gmail.com
Guest
Posts: n/a
 
      11th May 2007
I think u have to use ref keyword.


 
Reply With Quote
 
Alberto Poblacion
Guest
Posts: n/a
 
      11th May 2007
"Peted" wrote in message news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      11th May 2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass a byte array by reference sreelakshmi.rajula@gmail.com Microsoft Dot NET Framework 1 27th Nov 2006 07:54 PM
Pass Byte Array to web service kmercer46@yahoo.com Microsoft VB .NET 1 7th Jun 2006 04:27 AM
pass byte-array by reference from c# to managed c++ Jon Skeet [C# MVP] Microsoft C# .NET 16 10th Sep 2004 07:29 PM
Pass vb6 byte array to vb.net Metallicraft Microsoft VB .NET 0 18th Dec 2003 02:40 PM
Convert native byte array (pointer) to managed byte[] Dave Microsoft Dot NET 1 13th Aug 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.