1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| using static System.Runtime.InteropServices.JavaScript.JSType; namespace string的拘留池测试 { internal class Program { static void Main() { string str1 = "I am very happy!!"; string str2 = "I am very happy!!"; Console.WriteLine(object.ReferenceEquals(str1, str2));
char[] array1 = { 'I', ' ', 'a', 'm', ' ', 'v', 'e', 'r', 'y', ' ', 'h', 'a', 'p', 'p', 'y', '!', '!' }; string str4 = new string(array1); Console.WriteLine(object.ReferenceEquals(str1, str4)); Console.WriteLine("IsInterned(str2) = " + string.IsInterned(str2));
char[] array2 = { 't', 'e', 's', 't' }; string str5 = new string(array2); string str6 = string.IsInterned(str5); Console.WriteLine(str6 == null ? "null" : "not null");
string.Intern(str5); string str7 = string.IsInterned(str5); Console.Write($"IsInterned(str5) = {string.IsInterned(str5)}\n"); Console.WriteLine(str7 == null ? "null" : "not null");
Console.ReadKey();
} } }
|