Best way to “push” into C# array

后端 未结 12 2619
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 14:25

Good day all

So I know that this is a fairly widely discussed issue, but I can\'t seem to find a definitive answer. I know that you can do what I am asking for using a L

12条回答
  •  长发绾君心
    2021-02-13 14:45

    The is no array.push(newValue) in C#. You don't push to an Array in C#. What we use for this is a List. What you may want to consider (for teaching purpose only) is the ArrayList (no generic and it is a IList, so ...).

    static void Main()
    {
        // Create an ArrayList and add 3 elements.
        ArrayList list = new ArrayList();
        list.Add("One"); // Add is your push
        list.Add("Two");
        list.Add("Three");
    }
    

提交回复
热议问题