我有一个类:等同于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