Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("* DEMO GetHashCode *");

            var a = new Punto {
                X = 0, Y = 0
            };

            Console.WriteLine($"a(0,0){a.GetHashCode()}");

            var b = new Punto {
                X = 0, Y = 0
            };

            Console.WriteLine($"b(0,0){b.GetHashCode()}");

            var c = new Punto {
                X = 1, Y = 1
            };

            Console.WriteLine($"c(1,0){c.GetHashCode()}");

            var d = new Punto {
                X = 38, Y = 0
            };

            Console.WriteLine($"d(0,1){d.GetHashCode()}");
            var e = d;

            Console.WriteLine($"e(d){d.GetHashCode()}");

            Console.ReadLine();
        }
Пример #2
0
            static void Main(string[] args)
            {
                var p1 = new Punto {
                    X = 5, Y = 6
                };
                var p2 = new Punto {
                    X = 1, Y = 2
                };
                var p3 = new Punto {
                    X = 5, Y = 6
                };

                Console.WriteLine("p1.getHashCode() = {0}", p1.GetHashCode());
                Console.WriteLine("p2.getHashCode() = {0}", p2.GetHashCode());
                Console.WriteLine("p3.getHashCode() = {0}", p3.GetHashCode());

                Console.WriteLine("p1.Equals(p2) = {0}", p1.Equals(p2));
                Console.WriteLine("p2.Equals(p3) = {0}", p2.Equals(p3));
                Console.WriteLine("p3.Equals(p1) = {0}", p3.Equals(p1));

                Console.WriteLine("p1 == p2 = {0}", p1 == p2);
                Console.WriteLine("p2 == p3 = {0}", p2 == p3);
                Console.WriteLine("p3 == p1 = {0}", p3 == p1);
            }
Пример #3
0
 public void GetHashCodeDevuelveUnNumeroDistintoParaDosPuntosDistintos()
 {
     Punto pa = new Punto(3, 4);
     Punto pb = new Punto(2, 4);
     Assert.AreNotEqual(pa.GetHashCode(), pb.GetHashCode());
 }
Пример #4
0
 public void GetHashCodeDevuelveElMismoNumeroParaDosPuntoIguales()
 {
     Punto pa = new Punto(3, 4);
     Punto pb = new Punto(3, 4);
     Assert.AreEqual(pa.GetHashCode(),pb.GetHashCode());
 }