Пример #1
0
        public void TestGetHashCode_valuetype()
        {
            MyStruct s = new MyStruct();

            s.SetMsg("Hello");
            s.ID       = 1;
            s.Birthday = new DateTime(1981, 1, 1);

            Console.WriteLine(s.GetHashCode());
            Console.WriteLine(s.GetMsg().GetHashCode());
            //s.SetMsg("NewMsg");
            s.ID       = 2;
            s.Birthday = new DateTime(1981, 11, 11);
            Console.WriteLine(s.GetHashCode());
            Console.WriteLine(s.GetMsg().GetHashCode());

            MyStruct s2 = new MyStruct();

            s2.SetMsg(s.GetMsg());
            s2.ID = 3;
            Assert.AreEqual(s.GetHashCode(), s2.GetHashCode());
        }