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

       ArrayList alist = new ArrayList();
                //集合对像  长度可以改变,类型不限
    
    
                //添加单个元素可以Add()
                alist.Add("在在的");
                alist.Add(35);
                alist.Add(3.14);
                alist.Add('c');
                alist.Add(5000m);
    
    
                //如果用Add()添加数组或集合最好用  alist.AddRange()
                alist.AddRange(new int[] { 3, 43, 56, 7, 98, 7, 6, 5 });
                alist.AddRange(alist);
               // alist.Add(new int[] { 3, 43, 56, 7, 98, 7, 6, 5 });
                //会直接打印syste.int
                //if (alist[i] is int[])
                //{
                //    for (int j = 0; j < ((int[])alist[i]).Length; j++)
                //    {
                //        Console.WriteLine(((int[])alist[i])[j]);
                //    }
                //}
                //删除所有元素
                alist.Clear();
                
    
                //删除单个元素(写谁删谁)
                alist.Remove(5000m);
                
                //跟据下标删除元素
                alist.RemoveAt(0);
    
                //跟据下标移除一定范围的元素从1开始,删除3个
    
                //升序排列
                alist.Sort();
    
                //反转
                alist.Reverse();
    
                //在指定位置插入元素
                alist.Insert(1, 5000);
    
                //在指定位置插入集合
                alist.InsertRange(0,new int[]{ 3, 4, 54, 4, 23, 423, 465 });
    
                //
                bool b = alist.Contains(1);
    
                Console.WriteLine(b);
                alist.RemoveRange(1, 3);
                // object obj=new boject()   jalist.Add(obj)
                for (int i = 0; i < alist.Count; i++)
                {
                   
              
                    Console.WriteLine(alist[i]);
    
              
    
                }
                Console.ReadKey();
  • 相关阅读:
    LeetCode 264. Ugly Number II
    LeetCode 231. Power of Two
    LeetCode 263. Ugly Number
    LeetCode 136. Single Number
    LeetCode 69. Sqrt(x)
    LeetCode 66. Plus One
    LeetCode 70. Climbing Stairs
    LeetCode 628. Maximum Product of Three Numbers
    Leetcode 13. Roman to Integer
    大二暑假周进度报告03
  • 原文地址:https://www.cnblogs.com/zywf/p/4508385.html
Copyright © 2011-2022 走看看