SortedList By:Tanuj Kumar

Sortedlist collection
Sorted list
Sortedlist:
Represents a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
An introduction to DOT NET:
AddAdds an element with the specified key and value to a SortedList object.
ClearRemoves all elements from a SortedList object.
CloneCreates a shallow copy of a SortedList object.
ContainsDetermines whether a SortedList object contains a specific key.
ContainsKeyDetermines whether a SortedList object contains a specific key.
ContainsValueDetermines whether a SortedList object contains a specific value.
CopyToCopies SortedList elements to a one-dimensional Array object, starting at the specified index in the array.
Sorted 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;
using System.Collections;


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

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

                MessageBox.Show("Enter value in textboxes");
            }
            else
            {
                sl.Add(textBox1.Text, textBox2.Text);
                show();
                MessageBox.Show("added");
            }

        }
        public void show() {

            listBox1.Items.Clear();

            foreach (DictionaryEntry de in sl)
            {

                listBox1.Items.Add(de.Key +" "+de.Value);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (sl.Count <= 0)
            {

                MessageBox.Show("sortedlist is empty");
            }
            else
            {
                sl.Remove(textBox3.Text);
                show(); MessageBox.Show("removed successfully");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (sl.Contains(textBox4.Text))
            {
                MessageBox.Show("available");
            }
            else {

                MessageBox.Show("not available");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(sl.Count.ToString());
        }

       
    }
}

Posted By:Tanuj Kumar 
On:Shareyourconscience

SortedList By:Tanuj Kumar SortedList By:Tanuj Kumar Reviewed by Tanuj on 10:55:00 pm Rating: 5

No comments:

Powered by Blogger.