IEquatable<T> 接口类内重写Equals方法,就可以实现比较。IEqualityComparer<T> 接口可以写一个自定义类的比较类。可以重写GetHashCode()方法。
using System;
using System.Collections.Generic;
using System.Collections;
namespace Wrox
{
public class MainEntryPoint
{
static int Main(string[] args)
{
var janet = new Person{ FirstName = "Janet",LastName = "Jackson"};
Person[] persons1 = {
new Person
{
FirstName = "Michael",
LastName = "Jackson"
},
janet
};
Person[] persons2 = {
new Person
{
FirstName = "Michael",
LastName = "Jackson"
},
janet
};
if(persons1 != persons2)
Console.WriteLine("not the same reference.");
/*if((persons1 as IstructuralEquatable).Equals(persons2,EqualityComparer<Person>.Default))
{
Console.WriteLine("the same content.");
}*/
va