public override bool Equals(object obj)
{
//make sure the obj isnt null
if (obj == null)
{
return false;
}
//try casting it and comparing it
try
{
MatricesMatrix comparableMatricies = (MatricesMatrix)obj;
if (this.NumberOfColumns != comparableMatricies.NumberOfColumns || this.NumberOfRows != comparableMatricies.NumberOfRows)
{
return false;
}
for (int rowIndex = 0; rowIndex < this.NumberOfRows; rowIndex++)
{
for (int columnIndex = 0; columnIndex < this.NumberOfColumns; columnIndex++)
{
if (this.GetElement(rowIndex, columnIndex) != comparableMatricies.GetElement(rowIndex, columnIndex))
{
return false;
}
}
}
//if we didnt find a spot were it was not ewual than return true;
return true;
}
//if it was not a matix than they arent equal
catch (InvalidCastException)
{
return false;
}
}