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 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.

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

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

 Contains a specific key:

In order to check that whether the value of specified key is present in your sorted list or not, the sorted list class itself provides you a function named contains () which take an integer as an argument and tell whether the key is present or not. Its return type is Boolean.

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 (obj.Contains(key))

            {

                MessageBox.Show("given key is in the sorted list");

            }

            else

            {

                MessageBox.Show("key not found");

            }

        }

 

VB:

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

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

       If obj.Contains(key) Then

        MessageBox.Show("given key is in the sorted list")

    Else

        MessageBox.Show("key not found")

    End If

End Sub

 

Contains a specific value:

In order to check that whether the specified value is present in your sorted list or not, the sorted list class itself provides you a function named contains () which take an integer as an argument and tell whether the value is present or not. Its return type is Boolean.

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);

 

            if (obj.ContainsValue(value))

            {

                MessageBox.Show("given value is in the sorted list");

            }

            else

            {

                MessageBox.Show("value not found");

            }

           

        }

VB:

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

 

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

 

        If obj.ContainsValue(value) Then

            MessageBox.Show("given value is in the sorted list")

        Else

            MessageBox.Show("value not found")

 

        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 check that whether the given value and specific key of sorted list is present in list or not using “sorted list” class in Vb and c#.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< 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.

Disclaimer - Privacy
© 2002-2017 DevASP.net