Exemplo n.º 1
0
        static void Main()
        {
            // TEST PATH STORAGE
            Stack <Point3D> seq = new Stack <Point3D>();

            seq.Push(new Point3D(23, 11, 2));
            seq.Push(new Point3D(-23, 2, 11));
            seq.Push(new Point3D(23, 43, 89));

            Path.PathStorage.SavePath(seq, "path.txt");

            // TEST GENERIC LIST
            GenericList <int> myList = new GenericList <int>(8);

            myList.Add(23);
            myList.Add(12);
            myList.Add(55);
            myList.Add(78);
            myList.Add(-1);

            Console.WriteLine(myList.ToString());
            int currentCount = myList.Count;

            Console.WriteLine("Count: " + currentCount);
            Console.WriteLine("Index of 23: " + myList.IndexOf(23));
            Console.WriteLine("Index of 12: " + myList.IndexOf(12));
            myList.Insert(108, 2);
            Console.WriteLine("After insertion: " + myList);
            myList.RemoveAt(2);
            Console.WriteLine("Removed: " + myList);
            myList.Clear();
            Console.WriteLine("Cleared: " + myList);

            try
            {
                GenericList <string> newList = new GenericList <string>(4);
                newList.Add(null);
                // myList.Insert(23, 105);
                // myList.RemoveAt(-12);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            myList.Add(23);
            myList.Add(12);
            myList.Add(55);
            myList.Add(78);
            myList.Add(-1);

            // should resize
            myList.Add(44);
            myList.Add(5);
            myList.Add(7);
            myList.Add(886);
            myList.Add(-12);
            Console.WriteLine("Resize: ");
            Console.WriteLine(myList.ToString());
            Console.WriteLine(myList.Capacity);

            // min/max
            Console.WriteLine("Max: " + myList.Max <int>());
            Console.WriteLine("Min: " + myList.Min <int>());

            // Matrix operators
            Matrix <decimal> m1 = new Matrix <decimal>(2, 2);

            m1[0, 0] = 34;
            m1[0, 1] = 16;
            m1[1, 0] = -2;
            m1[1, 1] = -3;

            Matrix <decimal> m2 = new Matrix <decimal>(2, 2);

            m2[0, 0] = 16;
            m2[0, 1] = 34;
            m2[1, 0] = 2;
            m2[1, 1] = 0;

            Console.WriteLine("Operator overloading: ");
            Console.WriteLine(new string('-', 23) + "Add");
            Console.WriteLine(m1 + m2);
            Console.WriteLine(new string('-', 23) + "Subtract");
            Console.WriteLine(m1 - m2);
            Console.WriteLine(new string('-', 23) + "Multiply");
            Console.WriteLine(m1 * m2);

            Console.WriteLine((bool)m1);
            Console.WriteLine((bool)m2);

            // Show version at runtime
            Console.Write("Version: ");
            var atr = typeof(SimpleValidator).GetCustomAttributes(typeof(MyVersion), true).FirstOrDefault() as MyVersion;

            Console.WriteLine(atr != null ? atr.Version : "no version attribute");
        }
Exemplo n.º 2
0
        static void Main()
        {
            Console.WriteLine("First to test the paths:");
            Point3D a = new Point3D(2, -5, 3.5);
            Point3D b = new Point3D(-2, 25, 4.8);

            Console.WriteLine("Creating 2 point and print them:");
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine("Here is the static start: " + Point3D.PrintZero());
            Console.WriteLine("The distance between these two points is: " + StatisClass.Distance(a, b));
            Console.WriteLine("Read 4 points from txt and displaying them:");
            Path myPath = new Path(PathStorage.LoadPath());

            Console.WriteLine(myPath[0].ToString());
            Console.WriteLine(myPath[1].ToString());
            Console.WriteLine(myPath[2].ToString());
            Console.WriteLine(myPath[3].ToString());
            Console.WriteLine("And now save them to output.txt");
            PathStorage.SavePath(myPath);
            Console.WriteLine();
            Console.WriteLine("Now to test the Generic list. Create new list with size 2 and add two itens");
            GenericList <int> list = new GenericList <int>(2);

            list.Add(85);
            list.Add(12);
            Console.WriteLine(list);
            Console.WriteLine("Add one more item and let the list expand:");
            list.Add(-5);
            Console.WriteLine(list);
            Console.WriteLine("Print element at index 2: " + list[2]);
            list.RemoveAt(1);
            Console.WriteLine("Remove elemect at index 1: " + list);
            list.InsertAt(1, 99);
            Console.WriteLine("Insert elemect at index 1: " + list);
            Console.WriteLine("99 is which what index in the list: " + list.IndexOf(99));
            Console.WriteLine("Smallest element in the list is: " + list.Min());
            Console.WriteLine("Biggest element in the list is: " + list.Max());

            list.Clear();
            Console.WriteLine("Clearing the list." + list);

            Console.WriteLine("Now to test the matrixes: creating two matrixes: { 4, 3 }, { 2, 1 } and { 2, 1 }, { 4, 3 }, and them executing the 3 operations:");
            Matrix <int> firstMatrix  = new Matrix <int>(2, 2);
            Matrix <int> secondMatrix = new Matrix <int>(2, 2);

            int[,] sMatrix = new int[, ] {
                { 4, 3 }, { 2, 1 }
            };
            int[,] cMatrix = new int[, ] {
                { 2, 1 }, { 4, 3 }
            };
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    firstMatrix[row, col]  = sMatrix[row, col];
                    secondMatrix[row, col] = cMatrix[row, col];
                }
            }
            Console.WriteLine("Addition:");
            Matrix <int> newOne = firstMatrix + secondMatrix;

            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Subtraction:");
            newOne = firstMatrix - secondMatrix;
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Multiplication:");
            newOne = firstMatrix * secondMatrix;
            for (int row = 0; row < 2; row++)
            {
                for (int col = 0; col < 2; col++)
                {
                    Console.Write(newOne[row, col] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Atributes:");
            Type type = typeof(Test);

            object[] attr = type.GetCustomAttributes(false);
            foreach (VersionAttribute item in attr)
            {
                Console.WriteLine(item.Version);
            }
        }