If you have access to the code for the Address class, you can add the ability for them to compare themselves.
The following is a very naïve example. Comparing addresses is a very complex topic with many pitfalls.
public partial class Address : System.IEquatable<Address>
{
private static System.StringComparer comparer
= System.StringComparer.InvariantCultureIgnoreCase ;
public string Street1 { get ; private set ; }
public string Street2 { get ; private set ; }
public string CityStateZip { get ; private set ; }
private int hashcode ;
public Address
(
string Street1
,
string Street2
,
string CityStateZip
)
{
this.Street1 = Street1 ?? System.String.Empty ;
this.Street2 = Street2 ?? System.String.Empty ;
this.CityStateZip = CityStateZip ?? System.String.Empty ;
this.hashcode = ( this.Street1 + this.Street2 + this.CityStateZip ).GetHashCode() ;
return ;
}
public override int
GetHashCode
(
)
{
return ( this.hashcode ) ;
}
public override bool
Equals
(
object Op1
)
{
return ( this.Equals ( Op1 as Address ) ) ;
}
public virtual bool
Equals
(
Address Op1
)
{
return
(
( Op1 != null )
&&
( comparer.Compare ( this.Street1 , Op1.Street1 ) == 0 )
&&
( comparer.Compare ( this.Street2 , Op1.Street2 ) == 0 )
&&
( comparer.Compare ( this.CityStateZip , Op1.CityStateZip ) == 0 )
) ;
}
public static bool
operator ==
(
Address Op0
,
Address Op1
)
{
return ( Op0.Equals ( Op1 ) ) ;
}
public static bool
operator !=
(
Address Op0
,
Address Op1
)
{
return ( !Op0.Equals ( Op1 ) ) ;
}
}