// Accept if the argument is the same object as this.
if(ReferenceEquals(this,other))
{
returntrue;
}
// If all else fails, perform element wise comparison.
for(varrow=0;row<RowCount;row++)
{
for(varcolumn=0;column<ColumnCount;column++)
{
if(!At(row,column).Equals(other.At(row,column)))
{
returnfalse;
}
}
}
returntrue;
}
/// <summary>
/// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
/// </returns>
/// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>. </param><filterpriority>2</filterpriority>
publicoverridesealedboolEquals(objectobj)
{
returnEquals(objasMatrixStorage<T>);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
publicoverrideintGetHashCode()
{
varhashNum=Math.Min(RowCount*ColumnCount,25);
inthash=17;
unchecked
{
for(vari=0;i<hashNum;i++)
{
varcol=i%ColumnCount;
varrow=(i-col)/RowCount;
hash=hash*31+At(row,col).GetHashCode();
}
}
returnhash;
}
/// <remarks>Parameters assumed to be validated already.</remarks>