Assuming Flag
is one of your entity models, you could use a partial
class
and override Equals
and GetHashCode
. This also assumes that you have an Id
property on on your Flag
class
which uniquely identities it.
//this namespace MUST match the namespace of your entity model.
namespace Your.Entity.Model.Namespace
{
public partial class Flag
{
public override bool Equals(object obj)
{
var item = obj as Flag;
if (item == null)
{
return false;
}
return this.Id.Equals(item.Id);
}
public override int GetHashCode()
{
return this.Id.GetHashCode();
}
}
}
Usage would look like this
List<Flag> distinctFlags = allFlags.Distinct().ToList();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…