本文整理匯總了VB.NET中System.String.Intern方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET String.Intern方法的具體用法?VB.NET String.Intern怎麽用?VB.NET String.Intern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.Intern方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' 導入命名空間
Imports System.Text
Class Sample
Public Shared Sub Main()
Dim s1 As String = "MyTest"
Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString()
Dim s3 As String = String.Intern(s2)
Console.WriteLine($"s1 = {s1}")
Console.WriteLine($"s2 = {s2}")
Console.WriteLine($"s3 = {s3}")
Console.WriteLine($"Is s2 the same reference as s1?: {s2 Is s1}")
Console.WriteLine($"Is s3 the same reference as s1?: {s3 Is s1}")
End Sub
End Class
'
's1 = MyTest
's2 = MyTest
's3 = MyTest
'Is s2 the same reference as s1?: False
'Is s3 the same reference as s1?: True
'
示例2: StringBuilder
Dim s1 As String = "MyTest"
Dim s2 As String = New StringBuilder().Append("My").Append("Test").ToString()
Dim s3 As String = String.Intern(s2)
Console.WriteLine(CObj(s2) Is CObj(s1)) ' Different references.
Console.WriteLine(CObj(s3) Is CObj(s1)) ' The same reference.
示例3: CObj
Dim str1 As String = String.Empty
Dim str2 As String = String.Empty
Dim sb As StringBuilder = New StringBuilder().Append(String.Empty)
str2 = String.Intern(sb.ToString())
If CObj(str1) Is CObj(str2) Then
Console.WriteLine("The strings are equal.")
Else
Console.WriteLine("The strings are not equal.")
End If