Javatpoint Logo
Javatpoint Logo

VB.NET NameValueCollection

The NameValueCollcetion class is similar to HashTable that stores a collection of different data items in keys and associated values in string type. The class is provided by the System.Collection Namespace. The NameValueCollection can store more than one value under a single key separated by a comma.

Properties of the NameValueCollection Class

The following are the commonly used property of NameValueCollection:

Property name Description
AllKeys It is used to get all the keys in the NameValueCollection
Count It is used to count the number of key/value pair elements available in the NameValueCollection.
IsReadOnly It is used to get or set a value that determines whether the NameValueCollection is read-only.
Item It is used to get or set a value associated with the specified key in the NameValueCollection.
Keys It is used to get all the keys that have instances in the NameValueCollection.
Values It is used to obtain a collection of values in a NameValueCollection.

NameValueCollection Methods

The following are the commonly used methods of NameValueCollection.

Methods Name Description
Add It is used to add an element with the specified name and value into the NameValueCollection.
Syntax: NameValueCollection.Add(key, value)
Remove The Remove function is used to remove the specified key with the corresponding value.
Syntax: HashTable.Remove(Key)
Clear() It is used to remove all entries from the NameValueCollection.
Get(String) A Get() function is used to obtain a particular value of the specified index from the NameValueCollection that are comma-separated list.
Syntax: NameValueCollection.Get(Key)
HasKeys() A HasKeys() function is used to get a value that represents whether the NameValueCollection has keys that are not null.
Syntax: NameValueCollection.HasKey()
GetValues(String) It is used to get all the values of a specified key or index from the NameValueCollection.
Syntax: GetValues (ByVal str As String) As String()
Set() In NameValueCollection, a Set() function is used to set or overwrite the existing value of the key.
Syntax: Set(String, String)
Equals() The Equals() function is used to validate whether the specified object matches the current object.

Let us create a program to understand how we can add new elements to a NameVal array.

NameVal.vb

Output:

VB.NET NameValueCollection
Next TopicVB.NET List




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA