本文整理汇总了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