當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET RuntimeHelpers.GetHashCode方法代碼示例

本文整理匯總了VB.NET中System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET RuntimeHelpers.GetHashCode方法的具體用法?VB.NET RuntimeHelpers.GetHashCode怎麽用?VB.NET RuntimeHelpers.GetHashCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Runtime.CompilerServices.RuntimeHelpers的用法示例。


在下文中一共展示了RuntimeHelpers.GetHashCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

' 導入命名空間
Imports System.Runtime.CompilerServices

Module Example
   Public Sub Main()
      Console.WriteLine("{0,-18} {1,6} {2,18:N0}    {3,6} {4,18:N0}",
                        "", "Var 1", "Hash Code", "Var 2", "Hash Code")
      Console.WriteLine()
      
      ' Get hash codes of two different strings.
      Dim sc1 As String = "String #1"
      Dim sc2 As String = "String #2"
      ShowHashCodes("sc1", sc1, "sc2", sc2)
 
      ' Get hash codes of two identical non-interned strings.
      Dim s1 As String = "This string"
      Dim s2 As String = String.Format("{0} {1}", "This", "string")
      ShowHashCodes("s1", s1, "s2", s2)

      ' Get hash codes of two (evidently concatenated) strings.
      Dim si1 As String = "This is a string!"
      Dim si2 As String = "This " + "is " + "a " + "string!"
      ShowHashCodes("si1", si1, "si2", si2)
   End Sub
   
   Private Sub ShowHashCodes(var1 As String, value1 As Object, 
                             var2 As String, value2 As Object)
      Console.WriteLine("{0,-18} {1,6} {2,18:X8}    {3,6} {4,18:X8}",
                        "Obj.GetHashCode", var1, value1.GetHashCode,
                        var2, value2.GetHashCode)

      Console.WriteLine("{0,-18} {1,6} {2,18:X8}    {3,6} {4,18:X8}",
                        "RTH.GetHashCode", var1, RuntimeHelpers.GetHashCode(value1),
                        var2, RuntimeHelpers.GetHashCode(value2))
      Console.WriteLine()
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Runtime.CompilerServices,代碼行數:37,代碼來源:RuntimeHelpers.GetHashCode

輸出:

Var 1          Hash Code     Var 2          Hash Code

Obj.GetHashCode       sc1           94EABD27       sc2           94EABD24
RTH.GetHashCode       sc1           02BF8098       sc2           00BB8560

Obj.GetHashCode        s1           29C5A397        s2           29C5A397
RTH.GetHashCode        s1           0297B065        s2           03553390

Obj.GetHashCode       si1           941BCEA5       si2           941BCEA5
RTH.GetHashCode       si1           01FED012       si2           01FED012


注:本文中的System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。