Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to remove the value of specific index and the value having specific key in sorted list using “sorted list” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 947_sortedlist class.zip

In this simple article you will learn that how we can remove the value from a specific index and value of specific key in sorted list using “sorted list” class in Vb and c#.net.

 Remove a value from specific index:

To remove a value from the specific index of sorted list, sorted list class provides a function named removeAt which takes an integer value as an index and remove the value from that specific index.

To demonstrate make a new window application. Drag one button and a text box on from.

Now write the following code on Button click event:

C#:

private void button1_Click(object sender, EventArgs e)

{

int index = Convert.ToInt16(textBox1.Text);

 

            if (index < 0)

            {

                MessageBox.Show("invalid index");

            }

            else if (index > 6)

            {

                MessageBox.Show("out of bound");

            }

            else if (index > 0 && index < 6)

            {

                obj.RemoveAt(index);

                MessageBox.Show("element is removed from your sorted list");

            }

}

 

VB:

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)

Dim index As Integer = Convert.ToInt16(textBox1.Text)

If index < 0 Then

    MessageBox.Show("invalid index")

ElseIf index > 6 Then

    MessageBox.Show("out of bound")

ElseIf index > 0 AndAlso index < 6 Then

    obj.RemoveAt(index)

    MessageBox.Show("element is removed from your sorted list")

End If

Remove a value of specific key:

To remove a value of a specific key from the sorted list, the class has provide you a function remove which takes an integer value as an key and remove the value from the list having that key.

To demonstrate make a new window application. Drag one button and a text box on from.

Now write the following code on Button click event:

C#:

private void button2_Click(object sender, EventArgs e)

{

int key = Convert.ToInt16(textBox2.Text);

            if (key < 0)

            {

                MessageBox.Show("invalid key");

            }

            else if (key > 5)

            {

                MessageBox.Show("invalid key");

            }

            else if (key > 0 && key < 5)

            {

                obj.Remove(key);

                MessageBox.Show("key is removed from specific key");

            }

}

VB:

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim key As Integer = Convert.ToInt16(textBox2.Text)

    If key < 0 Then

        MessageBox.Show("invalid key")

    ElseIf key > 5 Then

        MessageBox.Show("invalid key")

    ElseIf key > 0 AndAlso key < 5 Then

        obj.Remove(key)

        MessageBox.Show("key is removed from specific key")

    End IF

End Sub

Now write the following code on FORM LOAD event:

C#

        private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP SORTED LIST APPLICATION";

           

            obj.Add(1, 20);

            obj.Add(2, 30);

            obj.Add(3, 40);

            obj.Add(4, 50);

            obj.Add(5, 60);

 

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP SORTED LIST APPLICATION"

       

        obj.Add(1, 20)

        obj.Add(2, 30)

        obj.Add(3, 40)

        obj.Add(4, 50)

        obj.Add(5, 60)

    End Sub

This simple article tells that how we can remove value from a specific index and of specific key of sorted list using “sorted list” class in Vb and c#.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to add, clear and getting total number of values in sorted list using “sorted list” class in VB and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net