Exemplo n.º 1
0
        /// <summary>
        /// Invokes a delegate when the value of the element of the matrix changed.
        /// </summary>
        /// <param name="e">Arguments of event.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <see cref="Matrix{T}.ValueChanged"/> equal to null.
        /// </exception>
        protected virtual void OnChange(MatrixEventArgs <T> e)
        {
            if (ReferenceEquals(ValueChanged, null))
            {
                throw new ArgumentNullException(nameof(ValueChanged));
            }

            ValueChanged(this, e);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The indexer for the <see cref="SquareMatrix{T}"/>.
        /// </summary>
        /// <param name="indexI">The row number.</param>
        /// <param name="indexJ">The column number.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when <paramref name="indexI"/> or/and <paramref name="indexJ"/> less than 0 or
        /// greater than or equal to the order of matrix.
        /// </exception>
        /// <returns>The element of matrix on passed indexes.</returns>
        public virtual T this[int indexI, int indexJ]
        {
            get
            {
                if ((indexI < 0) || (indexI >= _order))
                {
                    throw new ArgumentOutOfRangeException("Index i of the matrix element must be greater than 0 and less than order.", nameof(indexI));
                }

                if ((indexJ < 0) || (indexJ >= _order))
                {
                    throw new ArgumentOutOfRangeException("Index j of the matrix element must be greater than 0 and less than order.", nameof(indexI));
                }

                return(_matrix[indexI, indexJ]);
            }

            set
            {
                if ((indexI < 0) || (indexI >= _order))
                {
                    throw new ArgumentOutOfRangeException("Index i of the matrix element must be greater than 0 and less than order.", nameof(indexI));
                }

                if ((indexJ < 0) || (indexJ >= _order))
                {
                    throw new ArgumentOutOfRangeException("Index j of the matrix element must be greater than 0 and less than order.", nameof(indexI));
                }

                MatrixEventArgs <T> eventArgs = new MatrixEventArgs <T>()
                {
                    I        = indexI,
                    J        = indexJ,
                    OldValue = _matrix[indexI, indexJ],
                    NewValue = value
                };

                _matrix[indexI, indexJ] = value;

                OnChange(eventArgs);
            }
        }