Clears the entire collection : NameValueCollection « Data Structure « VB.Net

Clears the entire collection


Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesNameValueCollection
    Public Shared Sub Main()
        Dim myCol As New NameValueCollection()
        myCol.Add("A", "aa")
        myCol.Add("B", "bb")
        myCol.Add("C", "cc")
        myCol.Add("D", "dd")


    End Sub 'Main

    Public Shared Sub PrintKeysAndValues(myCol As NameValueCollection)
        Dim s As String
        For Each s In  myCol.AllKeys
            Console.WriteLine("   {0,-10} {1}", s, myCol(s))
        Next s
    End Sub 

    Public Shared Sub PrintKeysAndValues2(myCol As NameValueCollection)
        Dim i As Integer
        For i = 0 To myCol.Count - 1
            Console.WriteLine("   [{0}]     {1,-10} {2}", i, myCol.GetKey(i), myCol.Get(i))
        Next i
    End Sub
End Class


Related examples in the same category

1.Simple Demo for NameValueCollectionSimple Demo for NameValueCollection
2.NameValueCollection Class represents String keys and String values
3.Copies the values to a string array and displays the string array
4.Searches for a key and deletes it