zoukankan      html  css  js  c++  java
  • C#集合类使用范例

    //Dictionary
    System.Collections.DictionaryEntry dic=new System.Collections.DictionaryEntry("key1","value1");

    //ArrayList
    System.Collections.ArrayList list=new System.Collections.ArrayList();
    list.Add(
    1);//添加数据
    list.Add(2);
    for(int i=0;i<list.Count;i++)
    {
    System.Console.WriteLine(list[i]);
    //取出数据
    }


    //HashTable
    System.Collections.Hashtable table=new System.Collections.Hashtable();
    table.Add(
    "table1",1);//添加数据
    table.Add("table2",2);
    System.Collections.IDictionaryEnumerator d
    =table.GetEnumerator();//获取迭代器
    while(d.MoveNext())
    {
    System.Console.WriteLine(d.Entry.Key);
    //通过迭代器获取数据
    }

    System.Console.WriteLine(table[
    "table1"]);//直接读取数据

    //Queue
    System.Collections.Queue queue=new System.Collections.Queue();
    queue.Enqueue(
    1);//入队
    queue.Enqueue(2);

    System.Console.WriteLine(queue.Peek());
    //Queue.Peek()方法,取出队顶数据但不出队
    while(queue.Count>0)
    {
    System.Console.WriteLine(queue.Dequeue());
    //出队
    }


    //SortedList
    System.Collections.SortedList list=new System.Collections.SortedList();
    list.Add(
    "key2",2);//添加数据
    list.Add("key1",1);
    for(int i=0;i<list.Count;i++)
    {
    //打印输出,可以看出数据被排序了
    System.Console.WriteLine(list.GetKey(i));//获取关键字
    }


    //Stack
    System.Collections.Stack stack=new System.Collections.Stack();
    stack.Push(
    1);//入栈
    stack.Push(2);

    System.Console.WriteLine(stack.Peek());
    //Stack.Peek()方法,取出栈顶数据但不出栈
    while(stack.Count>0)
    {
    System.Console.WriteLine(stack.Pop());
    //出栈
    }

  • 相关阅读:
    手脱ASPack v2.12变形壳2
    手脱nSPack 2.1
    WCF分布式开发步步为赢(1):WCF分布式框架基础概念
    一个经典例子让你彻彻底底理解java回调机制
    C#三层架构详细解剖
    eclipse快捷键及各种设置
    设计模式总结
    程序猿也爱学英语(上)
    关于PDA、GPS等动态资源的几种GIS解决方案
    通过VS2010性能分析来查找代码中那些地方最损耗资源
  • 原文地址:https://www.cnblogs.com/ahuo/p/1052696.html
Copyright © 2011-2022 走看看