Copies the values to a string array and displays the string array
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")
Dim myStrArr(myCol.Count) As String
myCol.CopyTo(myStrArr, 0)
Console.WriteLine("The string array contains:")
Dim s As String
For Each s In myStrArr
Console.WriteLine(" {0}", s)
Next s
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