认识Object类

相信这个类,它的成员大家都熟记于心,做为.NET开发人员对于它的了解一定是最深的。再重复一下:

Equals 对象间比较

Finalize 资源回收

GetHashCode 生成一个与对象值相对应的数字以支持哈希表的使用

ToString 描述类的实例的可读文本字符串

using System;

class Point

{

private int x,y;

public Point(int x, int y)

{

       this.x = x;

       this.y = y;

}

public override bool Equals(object obj)

{

       if(obj == null || obj.GetType() != this.GetType() ) return false;

       Point other = (Point)obj;

       return (this.x == other.x)&&(this.y == other.y);

}

public override int GetHashCode()

{

      return x^y;

}

public override String ToString()

{

       return String.Format(“{0},{1}”,x,y);

}

public Point Copy()

{

      return (Pont) this.MemberwisClone();

}

}

Equals(Object)指定object 是否等于当前object

[s]Equals(Object, Object)

//以后再完善………

原文地址:https://www.cnblogs.com/chenqingwei/p/1724567.html