0%

C# Hashtable用法

C# Hashtable用法,C#有些东西使用方法还是跟Java不同,记一下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable table = new Hashtable();
            table.Add("a", "aaa");
            table.Add("c", "ccc");
            table.Add("b", "bbb");
            //添加元素 key,value

            IDictionaryEnumerator ide=table.GetEnumerator();
            while (ide.MoveNext()) {
                DictionaryEntry entry = ide.Entry;
                Console.WriteLine(entry.Key + "=" + entry.Value);
            }
            //循环输出所有键和值,不一定是按上面添加的顺序
            Console.WriteLine(table["b"]);
            //输出指定键的值 
            
            

        }
    }
}