// implementation of CompareTo method // comapres first by State,then City, // then streetName and Address number // then apartment unit // Exception if( Null object found ) public int CompareTo(Object alpha) { if (alpha == null) { throw new ArgumentNullException("Property object being compared with is NULL"); } Property rightOp = alpha as Property; if (rightOp != null) { if (State.ToLower().CompareTo(rightOp.State.ToLower()) == 0) { if (City.ToLower().CompareTo(rightOp.City.ToLower()) == 0) { if (StreetName.ToLower().CompareTo(rightOp.StreetName.ToLower()) == 0) { if (AddNumber.CompareTo(rightOp.AddNumber) == 0) { if (rightOp is Apartment) { Apartment rightObject = (Apartment)rightOp; Apartment thisObject = (Apartment)this; return(thisObject.Unit.ToLower().CompareTo(rightObject.Unit.ToLower())); } else { return(0); //becasue we have more typies of property now, if the addresses are the same, then the ranking of two properties are the same //throw new ArgumentNullException("Error:the address of house has been inputted"); } } else { return(AddNumber.CompareTo(rightOp.AddNumber)); } } else { return(StreetName.CompareTo(rightOp.StreetName)); } } else { return(City.CompareTo(rightOp.City)); } } else { return(State.CompareTo(rightOp.State)); } } else { throw new ArgumentNullException("Property object being compared with is NULL"); } }
// implementation of CompareTo method // comapres first by State,then City, // then streetName and Address number // then apartment unit // Exception if( Null object found ) public int CompareTo(Object alpha) { if (alpha == null) { throw new ArgumentNullException("Property object being compared with is NULL"); } Property rightOp = alpha as Property; if (rightOp != null) { if (State.CompareTo(rightOp.State) == 0) { if (City.CompareTo(rightOp.City) == 0) { if (StreetName.CompareTo(rightOp.StreetName) == 0) { if (AddNumber.CompareTo(rightOp.AddNumber) == 0) { if (rightOp is Apartment) { Apartment rightObject = (Apartment)rightOp; Apartment thisObject = (Apartment)this; return(thisObject.Unit.CompareTo(rightObject.Unit)); } else { throw new ArgumentNullException("Error:the address of house has beed inputted"); } } else { return(AddNumber.CompareTo(rightOp.AddNumber)); } } else { return(StreetName.CompareTo(rightOp.StreetName)); } } else { return(City.CompareTo(rightOp.City)); } } else { return(State.CompareTo(rightOp.State)); } } else { throw new ArgumentNullException("Property object being compared with is NULL"); } }
//public int ZipCode { get; set; } public int CompareTo(Address other) { int r = City.CompareTo(other.City); if (r == 0) { r = StreetName.CompareTo(other.StreetName); } if (r == 0) { r = Number.CompareTo(other.Number); } return(r); }