关于 Equal Override Overload 和 IEquatable
2024-10-18 23:25:37
namespace TestEqual
{
class Program
{
static void Main(string[] args)
{
Point2D a = new Point2D
{
X = ,
Y =
}; Point2D b = a; CallEquals(a, b);
a.Equals(b);
} public static void CallEquals<T>(T instance, T other)
{
instance.Equals(other);
}
} public struct Point2D
{
public int X;
public int Y; public override bool Equals(object obj)
{
if (!(obj is Point2D)) return false;
Point2D other = (Point2D) obj;
return X == other.X && Y == other.Y;
} public bool Equals(Point2D other)
{
return X == other.X && Y == other.Y;
}
}
}
CallEquals(a, b); 走 public override bool Equals(object obj)
a.Equals(b); 走 public bool Equals(Point2D other)
如果 struct Point2D 继承 IEquatable 则都会走 public bool Equals(Point2D other) 可以避免一次装箱
最新文章
- [译]用AngularJS构建大型ASP.NET单页应用(一)
- MVC WebAPI中响应客户端请求返回图片
- VS属性页的目录类型
- BZOJ3172[Tjoi2013]单词 题解
- SQL Server临界点游戏——为什么非聚集索引被忽略!
- 43.Android之ListView中BaseAdapter学习
- 让IE6下支持固定定位
- QStringList与QString互转
- ECSHOP在线手册布局参考图--商品详情页 goods.dwt
- Jemter
- 写一个Windows上的守护进程(6)Windows服务
- C语言 - 大小端问题
- 将本地代码上传到github
- python 基于机器学习识别验证码
- windows eclipse直接访问远程linux hadoop开发环境配置(符合实际开发的做法)
- loadrunner controller如何执行测试
- thinkphp5开发的网站出现”No input file specified”(php版本5.6.27)
- springcould
- 纯SVG实现的Loading动画,拿走不谢
- Python学习---抽屉框架分析[ORM操作]180314