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
 

Search value - get count - hash code and type of the list dictionary collection using ListDictionary class – vb.net - C# .net.

Author: Maliha Atteeq
Download Source Code : 992_listDictionary2.zip

In this simple article you will learn that how to search a value, get count, hash code, type of the list dictionary collection using ListDictionary class in vb and C# .net.

 Get count:

In order to get the total key-value pairs in the list dictionary collection, list dictionary class provides us a property known as Count. This property returns an integer which depicts the total key-value pairs in your list dictionary collection.

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

Now write the following code on Button click event:

C#:

private void btn_count_Click(object sender, EventArgs e)

        {

            int count;

            count=obj.Count;

            MessageBox.Show("total key-value pairs in list dictionary are "+Convert.ToString(count));

        }

 

VB:

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

        Dim count As Integer

        count = obj.Count

        MessageBox.Show("total key-value pairs in list dictionary are " + Convert.ToString(count))

    End Sub

Get type:

In order to get type of your collection, list dictionary class provides us a function named as getType(). This function takes no argument as a parameter. Its return type is system.type as it returns the object of class type .

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

Now write the following code on Button click event:

C#:

private void btn_type_Click(object sender, EventArgs e)

        {

            System.Type ob;

            ob = obj.GetType();

            MessageBox.Show("type of your collection is " + Convert.ToString(ob));

        }

VB:

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

        Dim ob As System.Type

        ob = obj.GetType()

        MessageBox.Show("type of your collection is " + Convert.ToString(ob))

    End Sub

Get Hash Code:

In order to get hash code of your list dictionary collection, list dictionary class provides a function named as getHashcode(). This function takes no argument as a parameter. Its return type is integer depicting the hash code of your list dictionary collection.

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

Now write the following code on Button click event:

C#:

private void btn_hashCode_Click(object sender, EventArgs e)

        {

            int code;

            code = obj.GetHashCode();

            MessageBox.Show("hash code of your list dictionary is "+Convert.ToString(code));

        }

VB:

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

        Dim code As Integer

        code = obj.GetHashCode()

        MessageBox.Show("hash code of your list dictionary is " + Convert.ToString(code))

    End Sub

Search the value:

In order to search a value in list dictionary collection, list dictionary collection class provides us a function named as contains(). This function takes one argument as a parameter which is the value to be searched. Its return type is Boolean. If the collection contains the specific value it will return true otherwise it will return false if the collection doesn’t contain.

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

Now write the following code on Button click event:

C#:

private void btn_search_Click(object sender, EventArgs e)

        {

            bool temp;

            int key;

            key = Convert.ToInt16(txt_key.Text);

            temp = obj.Contains(key);

            if (temp)

            {

                MessageBox.Show("the key is present in your list dictionary collection");              

            }

            else

            {

                MessageBox.Show("the key is not present in your list dictionary collection");

            }

        }

VB:

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

        Dim key As Integer

        Dim temp As Boolean

        value = Convert.ToInt16(txt_key.Text)

        temp = obj.Contains(key)

        If temp Then

            MessageBox.Show("the key is present in your list dictionary collection")

        Else

            MessageBox.Show("the key is not present in your list dictionary collection ")

        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 LIST DICTIONARY APPLICATION";

            obj.Add(1, 10);

            obj.Add(2, 20);

            obj.Add(3, 30);

            obj.Add(4, 40);

            obj.Add(5, 50);

          }

Vb:

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

        Me.Text = "DEVASP LIST DICTIONARY APPLICATION"

        obj.Add(1, 10)

        obj.Add(2, 20)

        obj.Add(3, 30)

        obj.Add(4, 40)

        obj.Add(5, 50)

    End Sub

This simple article tells that how to search a value, get count, hash code, type of the list dictionary collection using ListDictionary class in vb and C# .net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Use – initialize – add - clear and remove a key-value pair from the list dictionary collection using ListDictionary class – vb.net - C# .net.

Disclaimer - Privacy
© 2002-2017 DevASP.net