Reference or Value?

  • Thread starter Thread starter C# Learner
  • Start date Start date
C

C# Learner

In the following...

byte[] ReturnByteArray(int size)
{
byte[] result = new byte[size];

for (int i = 0; i < size; ++i) {
result = (byte)0;
}

return result;
}

....what is being returned - a reference or a value?

TIA
 
Hi C# Learner,
Just one tip. You don't need to zero the elements of the array. They are
guarantee to be 0.
When your variables are class members or elements of arrays (not local
variables created in the stack) you have guarantees that those variables or
array members have their default values.
For numbers default is 0, bool default is *false*, for enums whichever is
first or has value number 0 and for references the default value is *null*.

B\rgds
100
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top