Example #1
0
        static void RunTests_Struct()
        {
            Console.WriteLine("---------Value-------------");
            Stopwatch w = new Stopwatch();

            sVector v1 = new sVector(1, 1);
            sVector v2 = new sVector(2, 2);

            w.Start();
            // sVector v3 = Add(v1,v2);
            sVector v3 = v1 + v2;

            w.Stop();
            Console.WriteLine($"Time elapsed = {w.ElapsedTicks} ticks");
            Console.WriteLine($"{v1} + {v2} = {v3}");

            // copy by value, different objects
            var v4 = v3;

            Console.WriteLine($"v3 & v4 are same: {Object.ReferenceEquals(v3,v4)}");
            v4.X = 5;
            Console.WriteLine($"Modified v4. {v3} != {v4}");

            // hash codes - dictionary - maybe internally for gc
            Console.WriteLine($"Hashcodes : v1:{v1.GetHashCode()}, v2: {v2.GetHashCode()}," +
                              $"v3:{v3.GetHashCode()}, v4: {v4.GetHashCode()}");
        }
Example #2
0
        public static void RunTests_ArrayList()
        {
            Console.WriteLine("---------Array List-------------");
            // add a value vector object to an array list 100 times
            ArrayList l = new ArrayList();

            for (int i = 0; i < 100; i++)
            {
                var sV = new sVector(1, 1);
                l.Add(sV);
            }
        }
Example #3
0
        public static void RunTests_GenericList()
        {
            Console.WriteLine("---------Generic List-------------");
            // add a value vector object to a generice list
            // List<sVector> l = new List<sVector>();
            var l = new List <sVector>();

            for (int i = 0; i < 100; i++)
            {
                var sV = new sVector(1, 1);
                l.Add(sV);
            }
        }
Example #4
0
 static sVector Add(sVector v1, sVector v2)
 => new sVector(v1.X + v2.X, v1.Y + v2.Y);