473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

is a byte array Byte[] pass by reference

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
3 16620
I think u have to use ref keyword.
May 11 '07 #2
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gene | last post by:
I'm not sure I understand this behavior (at least in the context of C#). I understand the use of "ref" and "out" keywords as they apply to method arguments, and then something this morning...
2
by: nitin8or | last post by:
Hi ALL, I want to display in a RichTextBox the Binary Large Objects data coming from database. If I have one record its not a problem I convert it to byte array and pass it on in a stream as a...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
1
by: Drew | last post by:
Does this return the array by value or reference? Because of DotNet's memory handling, I don't know how I could figure this out... Is there a way? System::Byte...
3
by: Lee Crabtree | last post by:
I have a managed DLL that I've used to expose a C++ class. One of the functions in this class reads a line out of a file into a buffer of type "unsigned char*". Since all the data is just...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
6
by: Denis C | last post by:
Hi I have a byte array of length 2404. I want to access subsets of the array and pass the subset to the constructor of a class. i.e. Dim bData(2403) As Byte Dim aThing As SomeClass = new...
3
by: DaTurk | last post by:
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...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.