• Stack集合、queue集合、hashtable集合


    1.栈:Stack,先进后出,一个一个赋值,一个一个取值,按顺序。

    .count           取集合内元素的个数

    .push()         将元素一个一个推入集合中//stack集合存入用.push()

    .pop()           将元素一个个弹出集合

    .clear()         清空集合

     Stack s = new Stack();//先存入的后取出
                s.Push(1);
                s.Push(2);
                s.Push(3);
    
                Console.WriteLine(s.Pop()); //也可用foreach循环输出
                Console.WriteLine(s.Pop());

    2.queue:先存入的先输出,一个一个的赋值一个一个的取值,按照顺序。

    .count              取集合内元素的个数

    .Enqueue()      进队列集合//存入元素

    .Dequeue()      出队列集合

    .clear               清空集合

     //Queue q = new Queue();
                //q.Enqueue(1);
                //q.Enqueue(2);
                //q.Enqueue(3);
    
                //Console.WriteLine(q.Dequeue());
                //Console.WriteLine(q.Dequeue());

    3.hashtable:先进后出,一个一个赋值,但只能一起取值。

    .Add(,)              添加key和元素//用于元素添加

    .Remove()        将括号内的元素移除

    .contains()       判断集合中是否有括号内的元素

    .count               计算集合中元素的个数

    Hashtable h = new Hashtable();
    
                h.Add(1, "ss");
                h.Add(2, "dd");
    
                foreach (int i in h.Keys)//输出key
                {
                    Console.WriteLine(i);
                }
                Console.WriteLine("------");
                foreach (string s in h.Values)//输出key所对应的值
                {
                    Console.WriteLine(s);
                }
    
                Console.WriteLine("-----------");
                Console.WriteLine(h.Count);//输入一共元素的个数
                

  • 相关阅读:
    Spring AOP
    编写jQuery插件
    Linux下SVN服务器搭建
    Redis安装配置与Jedis访问数据库
    使用redis做mysql缓存
    $(document).ready(function(){})和$(window).load(function(){})的区别
    SSH三大框架简介
    docker inspect命令
    ELK 环境搭建3-Logstash
    ELK 环境搭建2-Kibana
  • 原文地址:https://www.cnblogs.com/franky2015/p/4646141.html
Copyright © 2020-2023  润新知