zoukankan      html  css  js  c++  java
  • 集合

     //集合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();
  • 相关阅读:
    UML-如何画操作契约?
    UML-操作契约是什么?
    UML-SSD总结
    UML-如何画SSD?
    UML-SSD-为什么要画SSD?
    UML-SSD-定义
    系统幂等性设计
    UML-领域模型-例子与总结
    UML-领域模型-属性
    UML-领域模型-添加关联和属性
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4823103.html
Copyright © 2011-2022 走看看