C# objects in arrayLists

后端 未结 4 770
北海茫月
北海茫月 2020-12-29 16:02

I\'m working with ArrayList in C# and I am wondering how I can add objects to an ArrayList and then retrieve the values from it?

In short,

4条回答
  •  萌比男神i
    2020-12-29 16:14

    Firstly, it is better to use a List, and not an ArrayList in C#. For instance, if you want a list of strings:

    List myList = new List();
    

    or

    var myList = new List();
    

    Then the methods will be similar, e.g.

    myList.Add("bla");
    var test = myList[0];
    

提交回复
热议问题