class TagComparer : IEqualityComparer<tag>
{
public bool Equals(tag x, tag y)
{
if (Object.ReferenceEquals(x, y)) return true;
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
return x.text == y.text && x.value == y.value;
}
public int GetHashCode(tag _tag)
{
if (Object.ReferenceEquals(_tag, null)) return 0;
int hashTagNameCode = _tag.text == null ? 0 : _tag.text.GetHashCode();
int hashTagValuCode = _tag.value.GetHashCode();
return hashTagNameCode ^ hashTagValuCode;
}
}
class tag
{
public tag(string txt, string val)
{
this.text = txt;
this.value = val;
}
public string text { get; set; }
public string value { get; set; }
}
eg:
private List<tag> listtag = new List<tag>();
var leftTag = listtag.Except(bindedTag, new TagComparer()).ToList(); //取差集