• hashtable and dictionary


          

    using System;
    using System.Collections.Generic;

    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                listBox1.Items.Clear();
                listBox2.Items.Clear();
                //using System.Collections;
                Hashtable ht = new Hashtable();
                ht.Add("001",1);
                ht.Add("002",2);
                ht.Add("003",3);

                foreach (string str in ht.Keys)
                {
                    listBox2.Items.Add(ht[str]);
                }
                foreach(DictionaryEntry h in ht)
                {
                    listBox1.Items.Add(h.Key);
                }
               


            }

            private void button2_Click(object sender, EventArgs e)
            {
                listBox2.Items.Clear();
                listBox1.Items.Clear();
                //using System.Collections.Generic;
                Dictionary<string, double> dictionary = new Dictionary<string, double>();
                dictionary.Add("001", 1);
                dictionary.Add("002", 2);
                dictionary.Add("003", 3);
                foreach (string str in dictionary.Keys)
                {
                    listBox2.Items.Add(dictionary[str]);
                }
                foreach(KeyValuePair<string ,double> kvp in dictionary)
                {
                    listBox1.Items.Add(kvp.Key);
                }
            }
        }
    }

  • 相关阅读:
    Ext.Msg.alert要注意的问题
    项目终于到了可以轻松下的时候,^_^
    Ext最佳应用
    Google居然无视中国人民的感情
    google的logo居然还是鲜艳色的!!!(下午已经是黑的了,还是感谢google)
    我们必须支持国产,这是义务
    管理软件更需要Open Social
    设计模式外观模式(Facade)
    设计模式代理模式(Proxy)
    设计模式桥接模式(Bridge)
  • 原文地址:https://www.cnblogs.com/zhangjun1130/p/1490676.html
Copyright © 2020-2023  润新知