本文整理汇总了VB.NET中System.Collections.Hashtable.ContainsValue方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Hashtable.ContainsValue方法的具体用法?VB.NET Hashtable.ContainsValue怎么用?VB.NET Hashtable.ContainsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable 的用法示例。
在下文中一共展示了Hashtable.ContainsValue方法的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(0, "zero")
myHT.Add(1, "one")
myHT.Add(2, "two")
myHT.Add(3, "three")
myHT.Add(4, "four")
' Displays the values of the Hashtable.
Console.WriteLine("The Hashtable contains the following values:")
PrintIndexAndKeysAndValues(myHT)
' Searches for a specific key.
Dim myKey As Integer = 2
Console.Write($"The key ""{myKey}"" is ")
If (myHT.ContainsKey(myKey))
Console.WriteLine("in the Hashtable.")
Else
Console.WriteLine("NOT in the Hashtable.")
End If
myKey = 6
Console.Write($"The key ""{myKey}"" is ")
If (myHT.ContainsKey(myKey))
Console.WriteLine(" in the Hashtable.")
Else
Console.WriteLine(" NOT in the Hashtable.")
End If
' Searches for a specific value.
Dim myValue As String = "three"
Console.Write("The value ""{0}"" is ", myValue)
If (myHT.ContainsValue(myValue))
Console.WriteLine(" in the Hashtable.")
Else
Console.WriteLine(" NOT in the Hashtable.")
End If
myValue = "nine"
Console.Write($"The value ""{myValue}"" is ")
If (myHT.ContainsValue(myValue))
Console.WriteLine(" in the Hashtable.")
Else
Console.WriteLine(" NOT in the Hashtable.")
End If
End Sub
Public Shared Sub PrintIndexAndKeysAndValues(myHT As Hashtable)
Dim i As Integer = 0
Console.WriteLine(vbTab + "-INDEX-" + vbTab + "-KEY-" + vbTab + "-VALUE-")
For Each de As DictionaryEntry In myHT
Console.WriteLine(vbTab + "[{0}]:" + vbTab + "{1}" + vbTab + "{2}", i, de.Key, de.Value)
i += 1
Next
Console.WriteLine()
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Collections,代码行数:66,代码来源:Hashtable.ContainsValue 输出:
The Hashtable contains the following values:
-INDEX- -KEY- -VALUE-
[0]: 4 four
[1]: 3 three
[2]: 2 two
[3]: 1 one
[4]: 0 zero
The key "2" is in the Hashtable.
The key "6" is NOT in the Hashtable.
The value "three" is in the Hashtable.
The value "nine" is NOT in the Hashtable.
注:本文中的System.Collections.Hashtable.ContainsValue方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论