如何获取系统对指定 String 的引用?
要访问系统对特定 String 的引用,代码如下:
示例
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); } }
输出
这将产生以下输出:
String1 = David System reference of String1 = David
示例
现在我们再看另一个示例:
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); } }
输出
这将产生以下输出:
String1 = 50 String2 = 100 System reference of String1 = 50
广告