コード例 #1
0
        public ImmutableMatrix Add(ImmutableMatrix other)
        {
            // for now, just assuming the matrices are the same size.

            int[,] resultData = new int[_data.GetLength(0), _data.GetLength(1)];

            for (int i = 0; i < _data.GetLength(0); i++)
            {
                for (int j = 0; j < _data.GetLength(1); j++)
                {
                    resultData[i, j] = _data[i, j] + other._data[i, j];
                }
            }

            return(new ImmutableMatrix(resultData));
        }
コード例 #2
0
        void TestingImmutableMatrix()
        {
            ImmutableMatrix matrix = new ImmutableMatrix(new int[, ]
            {
                { 2, 3 },
                { 0, -1 }
            });
            ImmutableMatrix matrix2 = new ImmutableMatrix(new int[, ]
            {
                { 0, 1 },
                { 1, 0 }
            });

            ImmutableMatrix matrix3 = matrix.Add(matrix2);
            // | 2  4 |
            // | 1 -1 |
        }