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
 
Back
Top