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
 

Use, Initialize, get - set the key and value of the object of dictionary entry collection using DictionaryEntry class vb.net - C# .net.

Author: Maliha Atteeq
Download Source Code : 1004_dictionaryEntry.zip

In this simple article you will learn that how to use, initialize, get/set the key and value of the object of dictionary entry collection using DictionaryEntry class in vb and C# .net.

 DictionaryEntry:

Each element of a collection based on IDictionary is a key-and-value pair, the element type is not the type of the key or the type of the value. Instead, the element type is DictionaryEntry.

Initialization:

In order to initialize the object of dictionary entry collection, dictionaryEntry class provides us with two overloaded constructors.

First constructor:

The first overloaded constructor is the blank constructor. It 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 button1_Click(object sender, EventArgs e)

        {

            System.Collections.DictionaryEntry obj = new System.Collections.DictionaryEntry();

            MessageBox.Show("dictionary entry is build using blank constructor.");

        }

 

VB:

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

        Dim obj As New System.Collections.DictionaryEntry()

        MessageBox.Show("dictionary entry is build using blank constructor.")

    End Sub

Second constructor:

The second overloaded constructor takes two arguments as a parameter which are key and value.

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

Now write the following code on Button click event:

C#:

 

private void btn_build2_Click(object sender, EventArgs e)

        {

            int key;

            int value;

            key = Convert.ToInt16(txt_key.Text);

            value = Convert.ToInt16(txt_value.Text);

            System.Collections.DictionaryEntry obj = new System.Collections.DictionaryEntry(key, value);

            MessageBox.Show("dictionary entry is build having key= "+Convert.ToString(key)+" and value = "+Convert.ToString(value));

 

        }

VB:

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

        Dim key As Integer

        Dim value As Integer

        key = Convert.ToInt16(txt_key.Text)

        value = Convert.ToInt16(txt_value.Text)

        Dim obj As New System.Collections.DictionaryEntry(key, value)

 

        MessageBox.Show(("dictionary entry is build having key= " & Convert.ToString(key) & " and value = ") + Convert.ToString(value))

    End Sub

Set/get the key:

In order to set or get the key of collection, dictionaryEntry class provides us a property named as key.

To set a key:

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

        {

            int key;

            key = Convert.ToInt16(txt_keey.Text);

            obj.Key = key;

            MessageBox.Show("key is set to "+Convert.ToString(key));

        }

VB:

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

        Dim key As Integer

        key = Convert.ToInt16(txt_keey.Text)

        obj.Key = key

        MessageBox.Show("key is set to " & Convert.ToString(key))

    End Sub

To get a key:

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

        {

            Object key;

            key = obj.Key;

            MessageBox.Show("key is "+Convert.ToString(key));

        }

VB:

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

        Dim key As [Object]

        key = obj.Key

        MessageBox.Show("key is " & Convert.ToString(key))

    End Sub

Set/get the value:

In order to set or get the value of collection, dictionaryEntry class provides us a property named as value.

To Set a value:

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

        {

            int value;

            value = Convert.ToInt16(txt_val.Text);

            obj.Value = value;

            MessageBox.Show("value is set to " + Convert.ToString(value));

 

        }

VB:

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

        Dim value As Integer

        value = Convert.ToInt16(txt_val.Text)

        obj.Value = value

 

        MessageBox.Show("value is set to " & Convert.ToString(value))

    End Sub

To get a value:

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

        {

            Object value;

            value = obj.Value;

            MessageBox.Show("value is " + Convert.ToString(value));

        }

VB:

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

        Dim value As [Object]

        value = obj.Value

        MessageBox.Show("value is " & Convert.ToString(value))

    End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP DICTIONARY ENTRY APPLICATION";

        }

 

Vb:

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

        Me.Text = "DEVASP DICTIONARY ENTRY APPLICATION"

    End Sub

This simple article tells that how to use, initialize, get/set the key and value of the object of dictionary entry collection using DictionaryEntry class in vb and C# .net.

Article Comments
good artical, i can understand this topic easily.

Posted on 3/15/2010 6:06:32 AM by sumaira

Hi,
System.Collections.DictionaryEntry obj = new System.Collections.DictionaryEntry();

am Added obj.key some collection of value.so am get value in obj.key one by one.
How get obj.Key Collection Value.

Posted on 3/28/2010 5:21:56 AM by sivakumar

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get Headers – Specific Header Contents and server name for response from server using HttpWebResponse class C#.net – vb.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net