Skip to main content

Nongeneric Collection:Hash Table By:Tanuj Kumar


Nongeneric Collection:Hash Table


Hash table :Nongeniric collection
Nongeneric Collection:Hash Table



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 hashtableprogram
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        String s;
        Hashtable ht = new Hashtable();


        private void button1_Click(object sender, EventArgs e)
        {
            ht.Add(textBox1.Text, textBox2.Text);
            listBox1 .Items .Clear ();
           foreach (DictionaryEntry de in ht)
            {
                listBox1.Items.Add(de.Key+" "+de.Value );
 
            }
            MessageBox.Show("saved");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("not working now");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                ht.Remove("1");
               
            ht.Remove(textBox3.Text);
                ht.Remove(textBox4.Text);
                listBox1.Items.Remove(textBox3.Text + " " + textBox4.Text);
                MessageBox.Show("deleted");
            }
            catch
            {
            MessageBox.Show ("Not Deleted");
            }
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
          
           
            if(ht.Contains (textBox5 .Text))
            {     MessageBox .Show ("available");
            }
            else
            {
            MessageBox .Show ("not available");
            }
            }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button7_Click(object sender, EventArgs e)
        {

            foreach (DictionaryEntry de in ht)
            {
                label3.Text = (de.Key + " " + de.Value);

            }
        }}}


hashtable assignment:



Hash table

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 hashtablewithfnlbutton
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Hashtable ht = new Hashtable();
        int i = 1,j;
       

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text==""||textBox2.Text== "") {

                MessageBox.Show("Enter name or Roll no.");
            }
            else {
               
                Class1 obj = new Class1();
                obj.Name = textBox1.Text;
                obj.Rollno = textBox2.Text;
                ht.Add(i, obj);
                i++;
          

            
                MessageBox.Show("saved");
            }



        }
     
 

        private void button5_Click(object sender, EventArgs e)
        {
            if (i == ht.Count)
            {

                MessageBox.Show("already on last");
            }
            else
            {
                i =ht.Count;
                Class1 obj = new Class1();
                obj = (Class1 )ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
           
           
            }
        }

       

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "")
            {
                MessageBox.Show("Enter input");
            }
            else
            {
                if(ht.Count ==0){
               
                 MessageBox.Show("no value stored");
                }else{j = int.Parse(textBox4.Text);
                      if (j == 0)
                {
                    MessageBox.Show("value starts from 1");
                }
                    else if (j <= ht.Count)
                {
                    Class1 obj = new Class1();
                    obj = (Class1)ht[j];
                    textBox1.Text = obj.Name;
                    textBox2.Text = obj.Rollno;
                }
              

                else
                {

                    MessageBox.Show("no valid input");
                }
            }}

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (i == 1)
            {
                MessageBox.Show("already on first record");
            }
            else
            {
                i = 1;
                Class1 obj = new Class1();
               obj =(Class1 ) ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (i == ht.Count)
            {
                MessageBox.Show("you already on last record");

            }
            else {
                i = i + 1;
                Class1 obj = new Class1();
                obj = (Class1)ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;

           
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (i == 1)
            {
                MessageBox.Show("already on first record");
            }
            else
            {
                i = i-1;
                Class1 obj = new Class1();
                obj = (Class1)ht[i];
                textBox1.Text = obj.Name;
                textBox2.Text = obj.Rollno;
            }
        }
    }
}
Classcoding:

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

namespace hashtablewithfnlbutton
{
    class Class1
    {
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        string rollno;

        public string Rollno
        {
            get { return rollno; }
            set { rollno = value; }
        }
    }
}

Posted By:Tanuj Kumar 
On:Shareyourconscience



Comments

Popular posts from this blog

Join the Beauty Course for Massage Beauty License Training

Massage Beauty School of California: Massage beauty program is one of the top ten beauty courses which are well recognized and sought after in the beauty sector. Several students from various cities and states enroll in this training program to get better learning opportunities and understand the minute technicalities of beauty massaging services. Certified schools and beauty institutes located in Los Angeles are offering cutting-edge training to the students who are eligible for the program. Palace Beauty College is an accredited beauty school that does offer a massage therapy program and also offers holistic learning facilities to the students. The college has years of experience in providing massage therapy license training in Los Angeles for more than half a decade now. The college maintains its official website to reach out to distant students and provide them relevant information related to the available beauty courses. The college takes pride in its impressive infrastru...

Having issue with MDaemon Outlook Connector to connect MDaemon data with Outlook

Migration from MDaemon to Outlook is the right way to access MDaemon data in Outlook by using Outlook Connector Migration from MDaemon to Outlook Without Outlook Connector Migration from MDaemon to Outlook Overview: MDaemon Mail Server provides Outlook Connector for MDaemon which let you view and open MDaemon data with Outlook. Using Outlook Connector users will be able to view MDaemon Mail and contacts in Outlook. But if have you deleted any file from MDaemon then it will also missing from Outlook as well.   The way MDaemon Outlook Connector works is by keeping a locally cached copy file of the mail body in a database and the attach   files as a separate file. This is completely different from Microsoft Outlook Exchange caching where everything is kept in one OST file. The problem with this is it takes around 30 minutes to open Outlook (from a cold boot) which is quite unacceptable!! Sometimes users couldn’t able to send and receive email while using Ou...

Most frequently asked interview question on String in java

 Here we describe difference between (==) and .equals() :- Both of them very much  differ  in their significance and working as equals() method is present in the java.lang.Object class and it is expected to check for the equivalence of the state of objects! That means, the contents of the objects. Whereas the '==' operator is expected to check the actual object instances are same or not. Let us see an example we have two String objects and they are being pointed by two different reference variables as a1 and a2. a1 = new String("xyz"); a2 = new String("xyz"); Now, if you use the "equals()" method to check for their equivalence as if(a1.equals(a2)) System.out.println("a1.equals(a2) is TRUE"); else System.out.println("a1.equals(a2) is FALSE"); You will get the output as TRUE as the 'equals()' method check for the content equivality. Lets check the '==' operator.. if(s...