See also:
Both of those questions are different in that they ask HOW you would change the size, to which I'm well aware that the answer is: "Don't ... use a list". They also reference a ref-based Array.Resize(ref array, int size)
.
My question is this:
Given that I have a monolithic legacy codebase, that I can't possibly examine the entirety of, and can't make any guarantees of what it does, ... if I have call method passing in a not-by-ref array, can I be guaranteed that the size of the array afterwards is unchanged.
Array.Resize isn't an issue, since the by-ref-ness would have to pass all the way up through the call stack, which it obviously doesn't.
But are there any other possible issues?
REMARKS ON NOT BEING A DUPLICATE
I'd argue that this is a different question from the others, because this is an "Is it possible?" rather than "how would I do it/what's the best way to do it". Thus answers that would be evil and wrong and would not be mentioned in the latter, would still be relevant to my question.
can I be guaranteed that the size of the array afterwards is unchanged.
Yes, because arrays never change size. Ever. Array.Resize
creates a new array and copies the data; it does not actually resize anything. If you have a reference to the old array, then: you're fine and the size is unchanging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With