重写equal,== !=
来源:互联网 发布:java学生信息录入系统 编辑:程序博客网 时间:2024/05/17 06:56
namespace RemoveDemo
{
public class Product
{
private string id = string.Empty ;
public Product(string id)
{
this.id = id;
}
public static Product GetProduct(string id)
{
return new Product(id);
}
public override bool Equals(System.Object obj)
{
// If parameter is null return false.
if (obj == null)
{
return false;
}
// If parameter cannot be cast to Point return false.
Product p = obj as Product;
if ((System.Object)p == null)
{
return false;
}
// Return true if the fields match:
return this.id == p.id;
}
public static bool operator ==(Product product1, Product product2)
{
// If both are null, or both are same instance, return true.
if (System.Object.ReferenceEquals(product1, product2))
{
return true;
}
// If one is null, but not both, return false.
if (((object)product1 == null) || ((object)product2 == null))
{
return false;
}
// Return true if the fields match:
return product1.id == product2.id;
}
public static bool operator !=(Product product1, Product product2)
{
// Return true if the fields match:
return product1 != product2;
}
public override int GetHashCode()
{
return base.GetHashCode() ^ Int32.Parse(id);
}
}
}
- 重写equal,== !=
- Java中关于==和equal的区别以及equals()方法重写
- Java 中equal() 方法与==的区别以及 equals()与 hashCode()方法重写
- equal重写
- ==与equal
- String == equal
- .equal 和 ==
- equal、hashcode、==
- == 和 equal
- == 和 equal()
- equal ==
- equal、hashcode ==
- equal与==
- equal == 区分
- ==和.equal(
- String、=、equal详解
- String用法详解(equal源码 ==和equal的解释、字面赋值和new赋值效率、重写了hashcode的方法解释)
- equal 和 == 区别
- C# 自动升级
- 三个不同形式的标准CSS选项卡及滑动门代码
- Linux Kernel and Android 休眠与唤醒(中文版)
- ActiveMQ极限性能参数测试结果
- 调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配
- 重写equal,== !=
- The Collection Interfaces in Java
- downlaod data from http with RandomAccessFile(muli Thread)
- 防编译代码
- 数据结构学习(十三)——插入排序
- boost bind使用指南
- 在命令行中的替换和截取字符串
- 错误Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.
- myeclipse6.5设置的debug不能被删除