Beispiel #1
0
        public static void Main(string[] args)
        {
            TwoDPoint point1 = new TwoDPoint(1, 10);
            TwoDPoint point2 = new TwoDPoint(1, 10);

            Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", point1.GetHashCode(), point2.GetHashCode());

            TwoDPointWithHash newPoint1 = new TwoDPointWithHash(1, 10);
            TwoDPointWithHash newPoint2 = new TwoDPointWithHash(10, 1);

            Console.WriteLine("Hash for point1: {0}\tHash for point2: {1}", newPoint1.GetHashCode(), newPoint2.GetHashCode());

            // уникальных точек будет 2, хотя координаты их одинаковы
            Console.WriteLine("TwoDPoint:");

            var twoDPointList = new List <TwoDPoint> {
                point1, point2
            };
            var distinctTwoDPointList = twoDPointList.Distinct();

            foreach (var point in distinctTwoDPointList)
            {
                Console.WriteLine("Distinct point: {0}", point);
            }

            // одна уникальная точка
            Console.WriteLine("TwoDPointWithHash:");

            var twoDPointWithHashList = new List <TwoDPointWithHash> {
                newPoint1, newPoint2
            };
            var distinctTwoDPointWithHashList = twoDPointWithHashList.Distinct();

            foreach (var point in distinctTwoDPointWithHashList)
            {
                Console.WriteLine("Distinct point: {0}", point);
            }
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            TwoDPointWithHash point1 = new TwoDPointWithHash(1, 1);
            TwoDPointWithHash point2 = new TwoDPointWithHash(10, 10);

            Console.WriteLine("Хеш код 1 = " + point1.GetHashCode());
            Console.WriteLine("Хеш код 2 = " + point2.GetHashCode());

            TwoDPointWithHash point3 = new TwoDPointWithHash(3, 3);
            TwoDPointWithHash point4 = new TwoDPointWithHash(4, 4);

            Console.WriteLine("Хеш код 3 = " + point3.GetHashCode());
            Console.WriteLine("Хеш код 4 = " + point4.GetHashCode());

            TwoDPointWithHash point5 = new TwoDPointWithHash(0, 0);
            TwoDPointWithHash point6 = new TwoDPointWithHash(0, 0);

            Console.WriteLine("Хеш код 5 = " + point5.GetHashCode());
            Console.WriteLine("Хеш код 6 = " + point6.GetHashCode());

            Console.ReadKey();
        }