[Solved] How can i add items to array to the start and to the end?


Firstly, I would only ever suggest using arrays for public vars to be edited in the inspector, for anything other than that they are too primitive.

If you are specifically needing to or wanting to use an array you will need to recreate it every time to add data or otherwise resize it.

Use lists though 😀

public class temp : MonoBehaviour {
public List<string> myList;
// Use this for initialization
void Start () {

    //initialize your list
    myList = new List<string> ();
    //add to your list
    myList.Add("some junk");
    string temp = "some more junk";
    myList.Add (temp);
    //add a new item at a specific index
    myList.Insert(0,"The new first item");
    //remove the first item: "The new first item"
    myList.RemoveAt(0);
    //remove everything
    myList.RemoveAll();


}

Note: Please consider correctly formatting your questions in the future as it becomes difficult for others to find information in the future resulting in duplicate questions 🙂

1

solved How can i add items to array to the start and to the end?