Thursday, 1 August 2013

Generic Collection:List By:Tanuj Kumar


Generic Collection:List
generic collection :
List<t>:

Generic Collection:List
        

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;


namespace listgeniriccollection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List<int > lst = new List<int >();
        private void button1_Click(object sender, EventArgs e)
        {
            int i=int.Parse(textBox1 .Text );
         
           lst.Add(i);
                show();
                    
        }
      
        public void show() {
            listBox1.Items.Clear();
            foreach (Object obj in lst)
            {
                listBox1.Items.Add(obj);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int i=int .Parse (textBox3 .Text );
            lst.Remove(i);
            MessageBox.Show("delete successfull");
            show();
        }

        private void button3_Click(object sender, EventArgs e)
        {int i=int.Parse (textBox2.Text );
        if (lst.Contains(i))
        {

            MessageBox.Show("available");
        }
        else {
            MessageBox.Show("Not available");
        }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar)) {

                e.Handled=true  ;
                MessageBox.Show("string is not supported");
            }
        }

    }
}

Designer.cs:
            // textbox1
            this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
            // textBox2
            this.textBox2.Location = new System.Drawing.Point(80, 76);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(100, 20);            this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  // textBox3
            this.textBox3.Location = new System.Drawing.Point(80, 114);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(100, 20);            this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPres);
Posted By:Tanuj Kumar 
On:Shareyourconscience

0 comments:

Post a Comment