首页 > 其他 > 详细

ArrayList的使用

时间:2019-08-05 09:22:36      阅读:117      评论:0      收藏:0      [点我收藏+]

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

namespace arraylist集合
{
  class Program
  {
    static void Main(string[] args)
  {
  //创建了一个集合对象
  ArrayList list = new System.Collections.ArrayList();
  //集合:很多数据的集合
  //数组:长度不可变、类型单一
  //集合的好处:长度可以任意改变,类型随便
  list.Add(1);
  list.Add(3.14);
  list.Add(true);
  list.Add("张三");
  list.Add(‘男‘);
  list.Add(5000m);
  //添加集合元素
  list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
  //list.AddRange(list);

  //list.Clear();清空所有元素
  //list.Remove(true);删一个元素
  //list.RemoveAt(0);根据下标索引删除元素
  //list.RemoveRange(0,3);根据下表移出一定范围的元素
  list.Sort();//升序排序
  list.Reverse();//反转
  list.Insert(1,"插入的");//插入单个元素
  list.InsertRange(0, new string[] { "张三" ,"李四"});
  bool b = list.Contains(1);//判断包含

  for (int i = 0; i < list.Count; i++)
  {

    Console.WriteLine(list[i]);
  }
  Console.ReadKey();
  }
 }
  public class Person
  {
    public void SayHello()
    {
    Console.WriteLine("我是人类");
    }
  }
}

ArrayList的使用

原文:https://www.cnblogs.com/lz-huihui/p/11300733.html

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