• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

lzhcode

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

ArrayList的使用

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("我是人类");
    }
  }
}

posted on 2019-08-05 00:34  lzhcode  阅读(113)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3