NameValueCollection Class represents String keys and String values
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")
PrintKeysAndValues(myCol)
PrintKeysAndValues2(myCol)
Console.WriteLine("Index 1 contains the value {0}.", myCol(1))
Console.WriteLine("Key ""red"" has the value {0}.", myCol("red"))
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