Skip to content

Instantly share code, notes, and snippets.

@yicone
Last active December 15, 2015 03:29
Show Gist options
  • Save yicone/5194704 to your computer and use it in GitHub Desktop.
Save yicone/5194704 to your computer and use it in GitHub Desktop.
这种情况,GetHaseCode该如何实现?
public class FlightsPlanEqualityComparer : IEqualityComparer<FlightsPlan>
{
public bool Equals(FlightsPlan x, FlightsPlan y)
{
if (x.Flights.Count != y.Flights.Count)
{
return false;
}
for (int i = 0; i < x.Flights.Count; i++)
{
var fx = x.Flights[i];
var fy = y.Flights[i];
if (fx.FlightNo != fy.FlightNo || fx.FlightSeat != fy.FlightSeat)
{
return false;
}
}
return true;
}
public int GetHashCode(FlightsPlan obj)
{
// FardId是FlightsPlan的唯一标识
//return obj.FareId.GetHashCode();
}
}
@oberxon
Copy link

oberxon commented Mar 19, 2013

return obj.FlightNo.GetHashCode()^obj.FlightSeat.GetHashCode()

@oberxon
Copy link

oberxon commented Mar 19, 2013

再加上那个count,没看到第一个判断

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment