Hash Table in C# progrmming
For Example: Write a program using Hash Table with windows form.
(First Create button and then set
Name properties as button1_Click_Click)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click_Click(object sender, EventArgs e)
{
Hashtable weeks = new Hashtable();
weeks.Add("1",
"SunDay");
weeks.Add("2",
"MonDay");
weeks.Add("3",
"TueDay");
weeks.Add("4",
"WedDay");
weeks.Add("5",
"ThuDay");
weeks.Add("6",
"FriDay");
weeks.Add("7",
"SatDay");
//Display a single Item
MessageBox.Show(weeks["5"].ToString());
//Search an Item
if
(weeks.ContainsValue("TueDay"))
{
MessageBox.Show("Find");
}
else
{
MessageBox.Show("Not
find");
}
//remove an Item
weeks.Remove("3");
//Display all key value pairs
foreach (DictionaryEntry day in
weeks)
{
MessageBox.Show(day.Key +
" - " + day.Value);
}
}
}
}
Output:
Comments
Post a Comment