Posted
Filed under .NET/C#
C# HashTable을 이용하여 국가를 검색하면 그 국가에 해당하는 꽃 이름이
꽃 이름을 통하여 검색하면 해당되는 국가가 나타나도록...
 
flower.cs
 class flower
    {
        private string fl;
        public string Flower
        {
            get
            {
                return fl;
            }
            set
            {
                fl = value;
            }
        }
    }

world.cs
 class world
    {
        private string wl;
        public string World
        {
            get
            {
                return wl;
            }
            set
            {
                wl = value;
            }
        }
    }

form.cs
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        flower fl = new flower();
        world wl = new world();
        
        Hashtable flower = new Hashtable();
        Hashtable world = new Hashtable();

        private void button1_Click(object sender, EventArgs e)
        {
            object o = textBox1.Text;
            textBox2.Text = flower[textBox1.Text].ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            fl.Flower = textBox1.Text;
            wl.World = textBox2.Text;

            flower.Add(fl.Flower, wl.World);
            world.Add(wl.World, fl.Flower);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            object o = textBox2.Text;
            textBox1.Text = world[textBox2.Text].ToString();
        }
    }
2010/01/03 20:52 2010/01/03 20:52