Exemple #1
0
        static void Main()
        {
            GenericClass <int> intList = new GenericClass <int>(3);

            intList.Add(1);
            intList.Add(2);
            intList.Add(3);
            intList.Min <int>();
            intList.Max <int>();
            Console.WriteLine(intList);
            intList.Add(5);
            Console.WriteLine(intList);
            //Console.WriteLine(intList.FindIndexOfElement(3));

            MatrixGeneric <int> matrix = new MatrixGeneric <int>(4);

            matrix[0, 0] = 4;
            MatrixGeneric <int> anotherMatrix = new MatrixGeneric <int>(4);

            matrix[0, 0] = 5;
        }
        public static MatrixGeneric <T> operator +(MatrixGeneric <T> matrixFirst, MatrixGeneric <T> matrixSecond)
        {
            if (matrixFirst.Rows != matrixSecond.Rows || matrixFirst.Cols != matrixSecond.Cols)
            {
                throw new ArgumentException("Matrices must be with the same length ot rows and cols!");
            }
            int currentRows           = matrixFirst.Rows;
            int currentCols           = matrixSecond.Cols;
            MatrixGeneric <T> current = new MatrixGeneric <T>(currentRows, currentCols);

            for (int i = 0; i < current.Rows; i++)
            {
                for (int j = 0; j < current.Cols; j++)
                {
                    dynamic m1CurrentVal = matrixFirst[i, j];
                    dynamic m2CurrentVal = matrixSecond[i, j];
                    current[i, j] = m1CurrentVal + m2CurrentVal;
                }
            }
            return(current);
        }