• 集合


     //集合ArrayList:跟数组比,不限数量,不限类型
               
                ArrayList arr = new ArrayList();
                arr.Add(5);
                arr.Add(7);
                arr.Add("fadf");
                string s = "你好";
                arr.Add(s);
                Console.WriteLine(arr[0]);
             
                int count = arr.Count;
                Console.WriteLine("元素个数为:" + count);
               // arr.Clear();//清空集合
                bool isok = arr.Contains(7);//包含
                Console.WriteLine(isok);
                
               // arr.Insert(2,"zhangsan");
    
               // arr.Remove("zhangsan");
               // arr.RemoveAt(2);
                
               int index =  arr.IndexOf("fadf");
               Console.WriteLine("索引为:"+index);
                foreach (object o in arr)
                {
                    Console.WriteLine(o);
                }
              
                //输入十个人的分数,放入集合当中
                ArrayList list = new ArrayList();
    
                for (int i = 0; i < 5; i++)
                {
                    string s = Console.ReadLine();
                    list.Add(s);
                }
    
                list.Sort();//排序
                list.Reverse();//翻转集合
    
                foreach (string s in list)
                {
                    Console.WriteLine(s);
                }
              
    
                //特殊集合stack queue hashtable
              
                //栈桥
                Stack s = new Stack();
                s.Push(3);//推入集合
                s.Push(5);
                s.Push(7);
    
                foreach(int a in s)
                {
                    Console.WriteLine(a);
                }
    
                int count = s.Count;
    
                int qu = int.Parse(s.Pop().ToString());//弹出最后一个元素
    
                Console.WriteLine(qu);
                s.Clear();//清空集合
              
                //队列
                Queue q = new Queue();
                q.Enqueue(3);
                q.Enqueue(5);
                q.Enqueue(7);
               
                int chu = int.Parse(q.Dequeue().ToString());
                foreach (int a in q)
                {
                    Console.WriteLine(a);
                }
            
    
                Hashtable hs = new Hashtable();
                hs.Add(3, "张三");
                hs.Add("4", "李四");
    
                //foreach (int i in hs.Keys)
                //{
                //    Console.WriteLine(i);
                //}
    
                foreach (string s in hs.Values)
                {
                    Console.WriteLine(s);
                }
    
                int count = hs.Count;//元素个数
    
                Console.WriteLine(hs["4"]);
    
                Console.ReadLine();
  • 相关阅读:
    1276
    1235
    1170
    Grids
    1137
    1127
    1076
    🍖Mysql三种模式的指定方式介绍
    🍖存储引擎介绍
    🍖MySQL库的详细操作
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4823103.html
Copyright © 2020-2023  润新知