Arrays in C# can't be appended-onto. What you might want instead is a List, which behaves a lot like an array, but you can add items to it:
// Declaration of member variable - you can initialize it at the same time.
public List<Transform> children = new List<Transform>();
// Populate the list's contents in a method like Start().
foreach(Transform child in this.transform)
You can still access the
ith item in the collection with
children[i] or iterate over everything in the collection with
foreach. The main difference is that if you want to know how many entries are in the collection, you need to use
.Count with Lists, as opposed to
.Length with Arrays.
Alternatively, you can pre-size the array to the size you need, then assign each entry one by one:
// Declaration of member variable - don't initialize it yet (we don't know the size yet).
public Transform children;
// Allocate an array of the right size and populate it inside a method like Start().
int childCount = transform.childCount;
children = new Transform[childCount];
for(int i = 0; i < childCount; i++)
children[i] = transform.GetChild(i);