码迷,mamicode.com
首页 > 其他好文 > 详细

ArrayList

时间:2016-04-19 14:04:02      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _004ArrayList集合
{
    class Program
    {
        static void Main(string[] args)
        {
            //ArrayList Hastable List<T> Dictionary<T,T>都是集合
            //int[]{} 是数组   数组不可以更改长度  集合长度可以随意更改
            Person p = new Person();
            ArrayList al = new ArrayList();
            //al.Add(1);
            //al.Add(‘c‘);
            //al.Add("李佳浩");
            //al.Add(new int[3]{1,2,3});
            //al.Add(p);
            //al.Add(al);
            //for (int i = 0; i < al.Count; i++)
            //{
            //    if (al[i] is Person)
            //    {
            //        ((Person)al[i]).SayHello();
            //    }
            //    else if (al[i] is int[])
            //    {
            //        for (int j = 0; j < ((int[])al[i]).Length; j++)
            //        {
            //            Console.WriteLine(((int[])al[i])[j]);
            //        }
            //    }else
            //    {
            //        Console.WriteLine(al[i]);
            //    }
            //}
            //Console.ReadLine();
            al.Add(1);
            al.Add("1234");
            al.AddRange(new string[]{"wang","li","daun"});
            //al.Clear();
            al.Insert(0,"准备好了吗");
            al.InsertRange(3,new int[]{111,111,111});
            //al.Remove("1234");
            //al.RemoveAt(2);
            al.RemoveRange(2, 3);
            for (int i = 0; i < al.Count; i++)
            {
                Console.WriteLine(al[i]);
            }
            Console.ReadLine();
        }
        public class Person
        {
            public void SayHello()
            {
                Console.WriteLine("我是人!");
            }
        }
    }
}

ArrayList

标签:

原文地址:http://www.cnblogs.com/lijiahao/p/5407580.html

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