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 get the index of the specified value, specified key and key of specified index using “sorted list” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 949_sorted list class.zip

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

 Get index of specific key:

In order to get the index of the specified key in the list, sorted List class gives you a function named indexOfKey which takes an integer as an input and returns the index of that specified key as an integer so its return type is integer.

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 key = Convert.ToInt16(textBox1.Text);

            if (key < 0)

            {

                MessageBox.Show("invalid key");

            }

            else if (key > 5)

            {

                MessageBox.Show("invalid key");

            }

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

            {

                String temp=Convert.ToString(obj.IndexOfKey(key));

                MessageBox.Show("key is found on"+temp);

            }

}

 

VB:

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

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

        If key < 0 Then

            MessageBox.Show("invalid key")

        ElseIf key > 5 Then

            MessageBox.Show("invalid key")

        ElseIf key > 0 AndAlso key < 5 Then

            Dim temp As [String] = Convert.ToString(obj.IndexOfKey(key))

            MessageBox.Show("key is found on" & temp)

        End If

    End Sub

 

Get index of specific value:

In order to get the index of the specified value in the list, sorted List class gives you a function named indexOfValue which takes an integer as an input and returns the index of that specified value as an integer so its return type is integer.

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 value = Convert.ToInt16(textBox2.Text);

            String temp = Convert.ToString(obj.IndexOfValue(value));

            MessageBox.Show("value is found on" + temp);

           

        }

VB:

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

 

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

        Dim temp As [String] = Convert.ToString(obj.IndexOfValue(value))

 

        MessageBox.Show("value is found on" & temp)

    End Sub

Get key of specified index:

In order to get the key of the specified index in the list, sorted List class gives you a function named getKey which takes an integer as an input and returns the key of that specified 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 button3_Click(object sender, EventArgs e)

{

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

            if (index < 0)

            {

                MessageBox.Show("invalid index");

            }

            else if (index > 5)

            {

                MessageBox.Show("invalid index");

            }

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

            {

                String temp=Convert.ToString(obj.GetKey(index));

                MessageBox.Show("key is found " + temp);

            }

}

VB:

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

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

        If index < 0 Then

            MessageBox.Show("invalid index")

        ElseIf index > 5 Then

            MessageBox.Show("invalid index")

        ElseIf index > 0 AndAlso index < 5 Then

            Dim temp As [String] = Convert.ToString(obj.GetKey(index))

            MessageBox.Show("key is found " & temp)

        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(0, 10);

            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(0, 10)

        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.

Article Comments
I have asp.net create folder how to fetch the sql username to that folder name same in side another folder automatically how to create using a asp.net

Posted on 12/26/2009 2:28:27 AM by vijay

Your artical very useful for me thank u.

Posted on 12/26/2009 2:30:48 AM by vijay

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to check that the value of specific index and the value having specific key is present in sorted list using “sorted list” class in vb and C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net