Creating constant Function to array elements that are continuous. C#

My question, to you, the community, is how would I call a single function to an array list of varying sizes of elements?

Say, you have the array set up and you can add array elements with gameobjects and their changeable varables, I will update with a script, once I arrive at my destination.

I’m building a simple way of adding extra scenery objects to the same function through inspector, for a mid term school project.

Any links to study and any C# scripting advice will be gladly inspected.

Okay, after re-reading this, I think I know what you are asking.

You may be used to C++, where changing the size of an array involves copying the elements over to a new one. By the way, that is a perfectly valid way of doing that in C#. You absolutely can use arrays and just make a new array of the size of the old array (simply someArray.Length in C#) plus the one you want to append, then loop through and change the values.

Or… you could use lists. A list in C# is a template array that can be any type, of arbitrary size, and allows things like searching through. They are accessed and work like an array, but easier. This is what the solution looks like in lists:

List<GameObject> YourObjects = new List<GameObject>();

void Start()
{
...stuff
    YourObjects.Add(SomeInitialObject);
}

...

void Update_Or_Whatever()
{
    YourObjects.Add(Object_That_Exists); 
    YourObjects.Add(GameObject.Instantiate(Resources.Load("object_that_doesnt_exist_yet"), wherever.transform.position, however.transform.rotation, whoever.transform));
    GameObject SomeObject = YourObjects[666];
}

If speed is a chief concern, but you don’t want to fuss with copying arrays, then consider a dictionary. They’re simple to use, don’t worry.