码迷,mamicode.com
首页 > Windows程序 > 详细

C#中添加对象到ArrayList的代码

时间:2019-01-05 19:56:23      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:方法   nbsp   The   tran   比较   pos   har   ddr   索引   

把开发过程中比较好的一些代码段做个备份,下面代码是关于C#中添加对象到ArrayList的代码。

ArrayList alcollect = new ArrayList();
string str = "learn csharp";
alcollect.Add(str);
alcollect.Add("hello world");
alcollect.Add(500);
alcollect.Add(new object());





AddRange方法支持添加一个范围内的对象。


ArrayList alcollect = new ArrayList();
string[] someArray = new string[] { "ek", "do", "theen" };
alcollect.AddRange(someArray);





Add和AddRange将对象添加到ArrayList的末尾。Insert和InsertRange方法添加对象到指定的索引位置。


ArrayList alcollect = new ArrayList();
alcollect.Insert(3, "adding this at 3rd posn");
string[] someStrings = new string[] { "hello", "world" };
alcollect.InsertRange(4, someStrings);





我们可以通过索引号找到指定的对象


ArrayList alcollect = new ArrayList();
alcollect[3] = "iam at three";





 

C#中添加对象到ArrayList的代码

标签:方法   nbsp   The   tran   比较   pos   har   ddr   索引   

原文地址:https://www.cnblogs.com/SHUN019/p/10225544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!