|RectangularMatrix Conversion (RectangularMatrix to SquareMatrix)|
public static explicit operator SquareMatrix ( RectangularMatrix A )
Public Shared Narrowing Operator CType ( A As RectangularMatrix ) As SquareMatrix
static explicit operator SquareMatrix^ ( RectangularMatrix^ A )
|InvalidCastException||The row and column dimensions of the matrix are not equal.|
It can occur that the mode of construction of a RectangularMatrix guarantees that it is actually square. For example, if you multiply an N X M rectangular matrix by an M X N rectangular matrix, the result is an N X N square matrix. However, when determining the type of the product, the .NET compiler considers only the types of the multiplicants. Since a RectangularMatrix times a RectangularMatrix yields a RectangularMatrix, it will consider the type of the product to be RetangularMatrix, even though its rows and column dimensions will be equal. You can use this explicit cast to obtain a SquareMatrix type.
Note that the output of the cast is not independent of the original matrix. This makes the cast operation fast, but changes to the resulting SquareMatrix will also change the original RectangularMatrix. To obtain an independent matrix, use the Copy method.