本文整理匯總了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
輸出:
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
輸出:
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
輸出:
s1 = s2: True String1 interned: Yes s3 = s4: False StringA interned: No