/// <summary> /// Returns True if the magnitude of this object is equivalent to that of the specified object. /// If the specified object is neither of type MM or Inch, false will be returned. /// </summary> /// <param name="obj">Object with which to compare this.</param> /// <returns>True if the magnitudes of this and the specified object are equivalent; false otherwise.</returns> public override bool Equals(object obj) { if (obj is Inch) { return(this == (Inch)obj); } if (obj is MM) { Inch objAsMM = (MM)obj; return(this == objAsMM); } return(Value == (double)obj); }
/// <summary> /// Returns True if the magnitude of this object is equivalent to that of the specified object to the specified number of decimal places. /// If the specified object is neither of type MM or Inch, false will be returned. /// </summary> /// <param name="obj">Object with which to compare this.</param> /// <param name="nDecPts">Number of decimal places to compare.</param> /// <returns>True if the magnitudes of this and the specified object are considered equivalent; false otherwise.</returns> public bool Equals(object obj, int nDecPts) { if (obj is MM) { Inch objAsInch = (MM)obj; double roundedObj = Math.Round(objAsInch.Value, nDecPts); double roundedMe = Math.Round(Value, nDecPts); return(roundedObj == roundedMe); } if (obj is Inch) { Inch objAsInch = (Inch)obj; double roundedObj = Math.Round(objAsInch.Value, nDecPts); double roundedMe = Math.Round(Value, nDecPts); return(roundedObj == roundedMe); } return(false); }