Since passing a C# array as a function parameter is pass-by-reference, that means I can modify the array in the function. So here I am trying to allocate and modify the array in the function:
void caller() {
int array[];
doStuff(array);
if (array != null) {
// never reaches here, even when I allocated the array of size 0
}
}
void doStuff(int[] array) {
int[] tmp = new int[0];
array = new int[tmp.Length];
}
Problem is that the array != null
check never turns out to be true, even when I have allocated an array of size 0. I've confirmed in documents that new int[0]
is a valid allocation command. What could I be doing wrong?