コード例 #1
0
        /// <summary>
        /// Gets the sub matrix.
        /// </summary>
        /// <param name="rowStart">The row start.</param>
        /// <param name="columnStart">The column start.</param>
        /// <param name="rowCount">The row count.</param>
        /// <param name="columnCount">The column count.</param>
        /// <returns>The sub matrix of the current matrix.</returns>
        public ObjectMatrix <T> GetSubMatrix(int rowStart, int columnStart, int rowCount, int columnCount)
        {
            if ((rowCount <= 0) || (columnCount <= 0))
            {
                throw new ArgumentException(Resources.ColumnAndRowCountBiggerThan0);
            }

            if ((rowStart < 0) || (columnStart < 0))
            {
                throw new ArgumentOutOfRangeException();
            }

            if (((rowStart + rowCount) > Rows) || ((columnStart + columnCount) > Columns))
            {
                throw new ArgumentOutOfRangeException();
            }

            ObjectMatrix <T> ret = new ObjectMatrix <T>(rowCount, columnCount);

            for (int i = rowStart; i < rowStart + rowCount; i++)
            {
                for (int j = columnStart; j < columnStart + columnCount; j++)
                {
                    ret[i - rowStart, j - columnStart] = this[i, j];
                }
            }

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">obj is not the same type as this instance. </exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (obj.GetType() == this.GetType())
            {
                ObjectMatrix <T> matrix = obj as ObjectMatrix <T>;
                return(this.Count.CompareTo(matrix.Count));
            }
            else
            {
                return(this.GetType().FullName.CompareTo(obj.GetType().FullName));
            }
        }