With a non-serialized field, you can set the length of the array using a field initializer:
private MyClass[] _value = { new(), new(), new() };
With a serialized field, you instead set the length of the array, and its contents, using the Inspector.
If you change the field initializer of a serialized array, it will only affect the default value in newly added components. For any components that already exist in your scenes and prefabs, their serialized values will override whatever was assigned using the field initializer.
[SerializeField] private MyClass[] _value; // <- doesn't even need a field initializer
Arrays have a fixed length, so you can’t resize an array object once it has been created.
The array object that is assigned to the _value field will always have a length of zero:
_value = new MyClass[0];
However, you can create a completely new array object with a different length, copy all items from the old array to the new array, and assign the new array into the same variable.
The Array.Resize method can be used to perform all these steps for you:
void AddToArray(MyClass item)
{
Array.Resize(ref _value, _value.Length + 1);
_value[_value.Length - 1] = item;
}
Side Note:
A little bit of “garbage” is generated every time you use Array.Resize, because the old array in the variable gets discarded, and the garbage collector needs to do a little bit of work to release it from memory. This is nothing to worry about at all in most cases, but if you do it every frame for example, then switching to use a List could be worth considering.
Side Note #2:
Even disregarding micro-optimizations, it’s in general considered good practice to prefer using an array when the size of the collection remains unchanged after initialization, and a List whenever the size can get changed after initialization. This way when somebody reads your code, the collection choice gives the reader a good hint about what to expect from the code.
So while using Array.Resize might make sense in your particular situation, to help avoid having to rewrite a lot of code, you should aim to use List.Add more often than that in the future.