首页 > Windows开发 > 详细

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

时间:2019-01-05 18:44:26      阅读:149      评论:0      收藏:0      [点我收藏+]

把开发过程中比较好的一些代码段做个备份,下面代码是关于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的代码

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!