zoukankan      html  css  js  c++  java
  • ArrayList集合--C#

     1 static void Main(string[] args)
     2         {
     3             //实例化出一个集合对象
     4             ArrayList list = new ArrayList();
     5 
     6             /*添加*/
     7             //--添加单个元素
     8             list.Add(1);
     9             list.Add('a');
    10             list.Add(1.23);
    11             list.Add("你好!");
    12             //--添加集合
    13             list.AddRange(new string[] { "abc", "def", "abc", "def", "abc" });
    14             list.AddRange(new int[] { 1, 2, 3, 4, 5 });
    15 
    16 
    17 
    18             /*删除*/
    19             list.Remove(1);//删除单个元素,写谁删除谁
    20             list.RemoveAt(0);//删除给定索引位置的元素
    21             list.RemoveRange(0, 2);//删除指定范围的元素,第一个是要删除的位置(索引号),第二个是要删除的个数(逻辑序号)
    22 
    23 
    24             /*清空*/
    25             list.Clear();
    26 
    27 
    28 
    29             /*倒置*/
    30             list.Reverse();
    31 
    32 
    33 
    34             /*插入*/
    35             list.Insert(1, "name");//将元素插入指定的索引出,第一个是指定的索引,第二个是要插入的值。
    36             list.InsertRange(1, new string[] { "tim", "kaidi", "luoli" });//将指定的集合插入其中。
    37 
    38 
    39 
    40             /*查找元素的索引*/
    41             int k = list.IndexOf('a');//根据所输入的元素值,查找索引
    42             Console.WriteLine(k);
    43 
    44 
    45 
    46             /*判断值是否存在*/
    47             bool fals;
    48             fals = list.Contains('a');
    49             Console.WriteLine(fals);
    50 
    51 
    52             /*遍历集合*/
    53             for (int i = 0; i < list.Count; i++)
    54             {
    55                 Console.WriteLine(list[i]);
    56             }
    57             Console.ReadKey();
    58         }
  • 相关阅读:
    好题Islands
    DB2的安装
    MariaDB存在的问题
    MariaDB 脚本
    SQL 执行顺序
    Maria数据库
    3 ignite windows 上安装
    Cassandra 学习七 cassandra研究
    Cassandra学习六 一些知识点
    Cassandra学习五 使用Key的正确姿势
  • 原文地址:https://www.cnblogs.com/KTblog/p/4456304.html
Copyright © 2011-2022 走看看