如何使用operator == if (obj == null) throw (new StackOverFlowException()); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样还是不能使得Main函数调用的Console.WriteLine(nullPoint == null);通过呀.抛出的异常你又是怎么处理呢? public static bool operator == (MyPoint p1, object p2) { if(p1==null&&p2!=null) return false; return p1.Equals(p2); } or public override bool Equals(object obj) { if(this==null&&obj!=null) return false; if (obj == null) return false; if(this.GetType() != obj.GetType()) return false; MyPoint p = (MyPoint)obj; if (p.x == this.x && p.y == this.y) return true; else return false; } 这样会有StackOverFlowException异常抛出,因为在operator == 中使用了== public static bool operator == (MyPoint p1, object p2) { object o1 = p1; object o2 = p2; if (o1 == o2) return true; else if (o1 == null || o2 == null) return false; return p1.Equals(p2); } to realljx(至尊十三少): 帮忙测试一下上面的代码.不修改Main函数.只要运行成功就可以了.thanks! 是不是MyPoint类没有继承Object? WinFomr里的DataGridView行高度不准确 Visual Studio 2008里写代码如何快速定位代码行? 利用FileSystemWatcher监视文件 一个for switch break的语法问题 去除相同的字符 关于routes.MapPageRoute的使用访法,请大家帮帮我,谢了 同样环境下获取cookie的有的行有的不行? 如何在C#中启动一个外部程序? 这个是什么语法,怎样用? 高兴!散分! 请问各位,有没有办法用编程的方法生成一个强类型的数据集? 遍历树型数据库表?(搞不出来就要要饭去了)
通过呀.抛出的异常你又是怎么处理呢?
{ if(p1==null&&p2!=null)
return false;
return p1.Equals(p2);
}
{
if(this==null&&obj!=null)
return false;
if (obj == null)
return false;
if(this.GetType() != obj.GetType())
return false;
MyPoint p = (MyPoint)obj;
if (p.x == this.x && p.y == this.y)
return true;
else
return false;
}
{
object o1 = p1;
object o2 = p2; if (o1 == o2)
return true;
else if (o1 == null || o2 == null)
return false;
return p1.Equals(p2);
}