2022-08-19【c#】string若只赋值无new无gc

using System;

namespace ConsoleApp1
{
    class Program
    {
        public class Test
        {
            string s1 = "123";
            const string s2 = "456";
            static string s3 = "789";

            public Test()
            {
                string s1_1 = s1;
                string s2_1 = s2;
                string s3_1 = s3;

                Console.WriteLine(s1.GetHashCode());
                Console.WriteLine(s1_1.GetHashCode());
                Console.WriteLine(s2.GetHashCode());
                Console.WriteLine(s2_1.GetHashCode());
                Console.WriteLine(s3.GetHashCode());
                Console.WriteLine(s3_1.GetHashCode());
            }
        }

        static void Main(string[] args)
        {
            Test t = new Test();
        }
    }
}

你可能感兴趣的:(2022-08-19【c#】string若只赋值无new无gc)