本文整理匯總了VB.NET中System.Collections.Hashtable.Clear方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Hashtable.Clear方法的具體用法?VB.NET Hashtable.Clear怎麽用?VB.NET Hashtable.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.Clear方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: SamplesHashtable
' 導入命名空間
Imports System.Collections
Public Class SamplesHashtable
Public Shared Sub Main()
' Creates and initializes a new Hashtable.
Dim myHT As New Hashtable()
myHT.Add("one", "The")
myHT.Add("two", "quick")
myHT.Add("three", "brown")
myHT.Add("four", "fox")
myHT.Add("five", "jumps")
' Displays the count and values of the Hashtable.
Console.WriteLine("Initially,")
Console.WriteLine($" Count : {myHT.Count}")
Console.WriteLine(" Values:")
PrintKeysAndValues(myHT)
' Clears the Hashtable.
myHT.Clear()
' Displays the count and values of the Hashtable.
Console.WriteLine("After Clear,")
Console.WriteLine($" Count : {myHT.Count}")
Console.WriteLine(" Values:")
PrintKeysAndValues(myHT)
End Sub
Public Shared Sub PrintKeysAndValues(myHT As Hashtable)
Console.WriteLine(vbTab + "-KEY-" + vbTab + "-VALUE-")
For Each de As DictionaryEntry In myHT
Console.WriteLine(vbTab + "{0}:" + vbTab + "{1}", de.Key, de.Value)
Next
Console.WriteLine()
End Sub
End Class
輸出:
Initially, Count : 5 Values: -KEY- -VALUE- two: quick five: jumps one: The three: brown four: fox After Clear, Count : 0 Values: -KEY- -VALUE-