我有一個類:等同於2個對象 - 每次都不同?
public class Person
{
public string name { get; set; }
public int age { get; set; }
}
Person p1 = new Person() { age=1, name="a" };
Person p2 = new Person() { age = 1, name = "b" };
我要像做
p1.equals(p2)
但年齡或名字
我不加入的方式是指字典(並使用Iequatable ...)
的Equals滿足HOD犯規採取任何助手裏面......
是沒有辦法,我可以給他我的具體的輔助類的任何方式就像:
Dictionary<PersonForDictionary, int> dct2 =
new Dictionary<PersonForDictionary, int>(new helperClass()); // here helperclass is a class which I gave him - and told the dictionary how to equate objects....
進出口尋找一個類似解決方案等同物體時。 (不在字典模式下)。
你的意思是,當你第一次稱它爲名字平等時,第二次爲年齡平等,然後再爲名字等等? – Tudor 2012-03-03 18:07:01
如果我把他的名字的比較對象轉移給他,所以按名字,年齡相同...(如果我把他比作年齡的對象,所以年齡...) – 2012-03-03 18:08:32