當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


VB.NET String Intern()用法及代碼示例

Intern() 方法用於係統對指定字符串的引用。

用法:

Function Intern(ByVal str as String) as String

參數:

  • Str:指定的字符串。

返回值:它返回係統對指定字符串的引用。

程序/源代碼:

下麵給出了演示 String 類的 Equals() 方法的源代碼。給定的程序已成功編譯並執行。

'VB.NET program to demonstrate the Intern() 
'method of String class.

Imports System

Module Module1
    Sub Main()
        Dim str1 As String = "hello World"
        Dim str2 As String = "Hello World"

        Console.WriteLine("System's reference of str1 #{0}#", String.Intern(str1))
        Console.WriteLine("System's reference of str2 #{0}#", String.Intern(str2))
    End Sub
End Module

輸出:

System's reference of str1 #hello World#
System's reference of str2 #Hello World#
Press any key to continue . . .

說明:

在上麵的程序中,我們創建了一個包含 Main() 函數的模塊 Module1。 Main() 函數是程序的入口點。

在 Main() 函數中,我們創建了兩個字符串 str1 和 str2。在這裏,我們獲取係統對指定字符串的引用,並在控製台屏幕上打印結果。





相關用法


注:本文由純淨天空篩選整理自 VB.Net program to demonstrate the Intern() method of String class。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。