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


VB.NET String.IsInterned方法代碼示例

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


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

示例1: Sample

' Sample for String.IsInterned(String)
Imports System.Text
Imports System.Runtime.CompilerServices

' In the .NET Framework 2.0 the following attribute declaration allows you to 
' avoid the use of the interning when you use NGEN.exe to compile an assembly 
' to the native image cache.
<Assembly: CompilationRelaxations(CompilationRelaxations.NoStringInterning)> 
Class Sample
    Public Shared Sub Main()
        ' String str1 is known at compile time, and is automatically interned.
        Dim str1 As [String] = "abcd"

        ' Constructed string, str2, is not explicitly or automatically interned.
        Dim str2 As [String] = New StringBuilder().Append("wx").Append("yz").ToString()
        Console.WriteLine()
        Test(1, str1)
        Test(2, str2)
    End Sub

    Public Shared Sub Test(ByVal sequence As Integer, ByVal str As [String])
        Console.Write("{0}) The string, '", sequence)
        Dim strInterned As [String] = [String].IsInterned(str)
        If strInterned Is Nothing Then
            Console.WriteLine("{0}', is not interned.", str)
        Else
            Console.WriteLine("{0}', is interned.", strInterned)
        End If
    End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:30,代碼來源:String.IsInterned

輸出:

1) The string, 'abcd', is interned.
2) The string, 'wxyz', is not interned.

If you use NGEN.exe to compile the assembly to the native image cache, this
example produces the following results:

1) The string, 'abcd', is not interned.
2) The string, 'wxyz', is not interned.

示例2: Example

Module Example
   Public Sub Main()
      Dim str1 As String = "a"
      Dim str2 As String = str1 + "b"
      Dim str3 As String = str2 + "c"
      Dim strings() As String = { "value", "part1" + "_" + "part2", str3, 
                                  String.Empty, Nothing }
      For Each value In strings
         If value Is Nothing Then Continue For
         
         Dim interned As Boolean = (String.IsInterned(value) IsNot Nothing)
         If interned Then
            Console.WriteLine("'{0}' is in the string intern pool.", 
                              value)
         Else
            Console.WriteLine("'{0}' is not in the string intern pool.",
                              value)                      
         End If
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:21,代碼來源:String.IsInterned

輸出:

value' is in the string intern pool.
part1_part2' is in the string intern pool.
abc' is not in the string intern pool.
is in the string intern pool.


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