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:
Add | Adds an element with the specified key and value to a SortedList object. |
Clear | Removes all elements from a SortedList object. |
Clone | Creates a shallow copy of a SortedList object. |
Contains | Determines whether a SortedList object contains a specific key. |
ContainsKey | Determines whether a SortedList object contains a specific key. |
ContainsValue | Determines whether a SortedList object contains a specific value. |
CopyTo | Copies SortedList elements to a one-dimensional Array object, starting at the specified index in the array. |
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
Comments
Post a Comment