面向对象进阶 04 集合


之前写过一篇关于数组文章,今天咱们来说一下“个人认为是数组的升级版-集合”。


1,关键字:ArrayList ;在用之前需要先引用一下,例:


using System.Collections;
ArrayList arrayList = new ArrayList
namespace System.Collections
{
    //
    // 摘要:
    //     使用大小会根据需要动态增加的数组来实现 System.Collections.IList 接口。若要浏览此类型的.NET Framework 源代码,请参阅
    //     Reference Source。
    [ComVisible(true)]
    [DebuggerDisplay("Count = {Count}")]
    [DebuggerTypeProxy(typeof(ArrayListDebugView))]
    [DefaultMember("Item")]
    public class ArrayList : IList, ICollection, IEnumerable, ICloneable
    {

2,之所以说是数组的升级版,是因为在数组里能够做的事情,在集合里照样能够完成,除此之外,集合还能做到数组做不到的一些东西,咱们来看下面的小实例:

class Program
    {
        static void Main(string[] args)
        {
            ArrayList arrayList = new ArrayList
            {
                1,
                3,
                5,
                7,
                9,
                "walawala",
                "哈哈",
                '男',
                18,
                3.14,
                85.1325646464646546546
            };

            //arrayList.Insert(1, 2);
            //arrayList.Insert(3, 4);
            //arrayList.Insert(5, 6);
            //arrayList.Insert(7, 8);
            //arrayList.Insert(9, 10);

            for (int i = 0; i < arrayList.Count; i++)
            {
                Console.WriteLine(arrayList[i]);
            }
            Console.ReadKey();
        }
    }

在集合里基本上是可以存储任何类型的数据,中间被注掉的部分代码,是集合的插入:Insert 。


3,这篇关于集合的文字就介绍到这里,个人建议,多用,多敲代码,熟练起来会不经意间 get 更多的东西。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值