List 或 Dictionary值如果是类对象,那么要在类中实现IEquatable相关接口
public class Seat : IEquatable<Seat>
{
#region Field
#endregion
#region Property
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// IP地址
/// </summary>
public IPAddress IpAddr { get; set; }
/// <summary>
/// 座位ID
/// </summary>
public int ID { get; set; }
/// <summary>
/// 是否在线
/// </summary>
public bool IsOnline { get; set; }
#endregion
#region Constructor
/// <summary>
///
/// </summary>
/// <param name="IpAddr"></param>
/// <param name="SeatName"></param>
public Seat()
{
this.IpAddr = IPAddress.Parse("127.0.0.1");
this.Name = "未定义";
}
/// <summary>
///
/// </summary>
/// <param name="IpAddr"></param>
/// <param name="SeatName"></param>
public Seat(IPAddress IpAddr, string SeatName)
{
this.IpAddr = IpAddr;
this.Name = SeatName;
}
#endregion
#region IEquatable
/// <summary>
///
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(Seat other)
{
if (other == null)
return false;
if (this.Name == other.Name)
return true;
else
return false;
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(Object obj)
{
if (obj == null)
return false;
if (obj as Seat == null)
return false;
else
return Equals(obj as Seat);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return this.Name.GetHashCode();
}
/// <summary>
///
/// </summary>
/// <param name="client1"></param>
/// <param name="client2"></param>
/// <returns></returns>
public static bool operator ==(Seat client1, Seat client2)
{
if (((object)client1) == null || ((object)client2) == null)
return Object.Equals(client1, client2);
return client1.Equals(client2);
}
/// <summary>
///
/// </summary>
/// <param name="client1"></param>
/// <param name="client2"></param>
/// <returns></returns>
public static bool operator !=(Seat client1, Seat client2)
{
if (((object)client1) == null || ((object)client2) == null)
return !Object.Equals(client1, client2);
return !(client1.Equals(client2));
}
#endregion
}