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


VB.NET Object.ReferenceEquals方法代碼示例

本文整理匯總了VB.NET中System.Object.ReferenceEquals方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Object.ReferenceEquals方法的具體用法?VB.NET Object.ReferenceEquals怎麽用?VB.NET Object.ReferenceEquals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


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

示例1: App

Public Class App
    Public Shared Sub Main() 
        Dim o As Object = Nothing
        Dim p As Object = Nothing
        Dim q As New Object
        Console.WriteLine(Object.ReferenceEquals(o, p))
        p = q
        Console.WriteLine(Object.ReferenceEquals(p, q))
        Console.WriteLine(Object.ReferenceEquals(o, p))
    End Sub 
End Class
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:11,代碼來源:Object.ReferenceEquals

輸出:

True
True
False

示例2: Example

Public Module Example
   Public Sub Main
      Dim int1 As Integer = 3
      Console.WriteLine(Object.ReferenceEquals(int1, int1))
      Console.WriteLine(int1.GetType().IsValueType)
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:7,代碼來源:Object.ReferenceEquals

輸出:

False
True

示例3: Example

Module Example
   Public Sub Main()
      Dim s1 As String = "String1"
      Dim s2 As String = "String1"
      Console.WriteLine("s1 = s2: {0}", Object.ReferenceEquals(s1, s2))
      Console.WriteLine("{0} interned: {1}", s1, 
                        If(String.IsNullOrEmpty(String.IsInterned(s1)), "No", "Yes"))

      Dim suffix As String = "A"
      Dim s3 = "String" + suffix
      Dim s4 = "String" + suffix
      Console.WriteLine("s3 = s4: {0}", Object.ReferenceEquals(s3, s4))
      Console.WriteLine("{0} interned: {1}", s3, 
                        If(String.IsNullOrEmpty(String.IsInterned(s3)), "No", "Yes"))
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:16,代碼來源:Object.ReferenceEquals

輸出:

s1 = s2: True
String1 interned: Yes
s3 = s4: False
StringA interned: No


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