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
 

Get count - privileges, - read-only copy and find key in ordered dictionary using OrderedDictionary class VB.NET - C# .NET.

Author: Maliha Atteeq
Download Source Code : 986_orderedDictionary2.zip

In this simple article you will learn that how to get count, privileges, read-only copyand to find that key is present in ordered dictionary collection using OrderedDictionary class in vb and C# .net.

 Contains key or not:

In order to find that the specified key is present in your ordered dictionary or not, ordered dictionary class provides us a function named as contains(). This function takes one argument as a parameter and that is the key. Its return type is Boolean. If the key is present in the ordered dictionary, it will return true otherwise it will return false.

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_contains_Click(object sender, EventArgs e)

        {

            int key;

            key = Convert.ToInt16(txt_key.Text);

            if (obj.Contains(key))

            {

                MessageBox.Show("Given key is present in ordered dictionary");

            }

            else

            {

                MessageBox.Show("Given key is not present in ordered dictionary");

            }

 

        }

VB:

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

        Dim key As Integer

        key = Convert.ToInt16(txt_key.Text)

        If obj.Contains(key) Then

            MessageBox.Show("Given key is present in ordered dictionary")

        Else

            MessageBox.Show("Given key is not present in ordered dictionary")

 

        End If

    End Sub

To get count:

In order to get total number of key-value pair in your ordered dictionary, ordered dictionary class provides us a property known as COUNT. This property returns the total number of key-value pair in your ordered dictionary as its return type is integer.

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 button1_Click(object sender, EventArgs e)

        {

            int count;

            count=obj.Count;

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

        }

VB:

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

        Dim count As Integer

        count = obj.Count

 

        MessageBox.Show("total key-value pairs are " & Convert.ToString(count))

    End Sub

To check the preivilages:

In order to check the preivilages on your ordered dictionary, ordered dictionary class provides us a property known as IsReadOnly. Its return type is boolean. If the ordered dictionary is read only then it will return true and if it return false it means that your ordered dictionary is not read only.

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_check_Click(object sender, EventArgs e)

        {

            bool temp;

            temp = obj.IsReadOnly;

            if (temp)

            {

                MessageBox.Show("your ordered dictionary is read only");

            }

            else

            {

                MessageBox.Show("your ordered dictionary is not read only");

            }

        }

VB:

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

        Dim temp As Boolean

        temp = obj.IsReadOnly

        If temp Then

            MessageBox.Show("your ordered dictionary is read only")

        Else

            MessageBox.Show("your ordered dictionary is not read only")

        End If

    End Sub

AS read only:

In order to get a read only copy of your ordered dictionary collection, ordered dictionary class provides us a property named as AsReadOnly. It returns the object of ordered dictionary which contains the copy of  read only pairs of key-value. This function takes no argument as a parameter.

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_asreadonly_Click(object sender, EventArgs e)

        {

            System.Collections.Specialized.OrderedDictionary ob;

            ob = obj.AsReadOnly();

            int i = 0;

            while (i < ob.Count)

            {

                MessageBox.Show(Convert.ToString(ob[i]));

                i++;

            }

          

        }

VB:

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

        Dim ob As System.Collections.Specialized.OrderedDictionary

        ob = obj.AsReadOnly()

        Dim i As Integer = 0

        While i < ob.Count

            MessageBox.Show(Convert.ToString(ob(i)))

            i += 1

 

        End While

    End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP ORDERED 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 ORDERED 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 get count, privileges, read-only copyand to find that key is present in ordered dictionary collection using OrderedDictionary class in vb and C# .net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Initialize - add and clear the ordered dictionary using OrderedDictionary class – vb.NET - C# .NET.

Disclaimer - Privacy
© 2002-2017 DevASP.net