Why can't you add items to arrays in a loop?
.net, c#
Solution
Arrays are not resizable because that's how memory works. Getting into how memory allocation works exactly in .NET is a little much for an SO answer, you can read all about it elsewhere if you want, but one aspect is basically universal across every platform: when you have a piece of memory allocated for something, the next address after that something might be part of some other thing.
So you can't just expand a piece of memory and hope nothing goes wrong, you'd have to test that you can expand it and have a plan B for when you can't - that plan B will be allocating a new block of memory, copying the old thing into it, and deallocating the old block.
To avoid reallocating and copying many times, it's common practice to make the new block twice as big as the old block, so if you add `n` items, you will only reallocate© `O(log n)` times, keeping the amortized time for adding a new item to a dynamically-grown array down to O(1). So constant time, great - not really. It's still more time than if you didn't have to reallocate, and in fact even every `add` that doesn't cause a grow has a little overhead to make sure that no grow is necessary yet.
So, arrays that don't grow are a lot simpler, a little faster, and waste less memory. So in C# (and many other languages, such as Java and C++) you get to choose: do you want to use a growable "array-like-thing", or a non-growable one? There is a trade-off there, and these languages choose not to take that decision for you.
Problem
Why is it that within C# you can't add objects to an array unless you declare the length of the array or add the item straight away? For example I could not simply do this ``` foreach(object item in array) { array.Add(item) } ``` I would have to create a list and convert it to an array after the loop. I do not want to know how to do, I want to have a logical explination of WHY arrays are fixed lengths but other collections aren't (List, ListArray)