当前位置: 首页>>代码示例>>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;未经允许,请勿转载。