Để truy xuất tham chiếu của hệ thống tới Chuỗi được chỉ định, mã như sau -
Ví dụ
using System;
public class Demo{
public static void Main(string[] args){
string str1 = "David";
string str2 = string.Intern(str1);
Console.WriteLine("String1 = "+str1);
Console.WriteLine("System reference of String1 = "+str2);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
String1 = David System reference of String1 = David
Ví dụ
Bây giờ chúng ta hãy xem một ví dụ khác -
using System;
public class Demo{
public static void Main(string[] args){
string str1 = "50";
string str2 = "100";
Console.WriteLine("String1 = "+str1);
Console.WriteLine("String2 = "+str2);
str2 = string.Intern(str1);
Console.WriteLine("System reference of String1 = "+str2);
}
} Đầu ra
Điều này sẽ tạo ra kết quả sau -
String1 = 50 String2 = 100 System reference of String1 = 50