Part 57 Why should you override ToString Method

sometimes you can override ToString method like that:

namepace Example

public class MainClass
{
  Customer C = new Customer();
  C.firstName = "Lin";
  C.lastName="Gester";
  Console.Write(C.ToString()); //it will write Lin Gester;
}
public class Customer
{
  public string FirstName{get;set;}
  public string LastName{get;set;}
  public override string ToString()
  {
    return this.FirstName+""+this.LastName;
  }
}

Part 58  Why should you override Equals Method

public class MainClass
{
private static void Main()
{
Customer C1 = new Customer();
C1.FirstName = "Lin";
C1.LastName = "Gester";
Customer C2 = new Customer();
C2.FirstName = "Lin";
C2.LastName = "Gester";
Console.Write(C1==C2);
Console.Write(C1.Equals(C2)); }
}
public class Customer
{
public string FirstName{get;set;}
public string LastName{get;set;}
public override bool Equals(Object obj)
{
if(obj==null)
{
return false;
}
if(!(obj is Customer))
{
return false;
}
return this.FirstName==((Customer)obj).FirstName&&this.LastName==((Customer)obj).LastName;
}
}

Part 57 to 58 Why should you override ToString and Equal Method的更多相关文章

  1. C#中 ToString 和 override ToString 的区别

    public class p { public string ToString(){ return "p"; } } public class c:p{ public string ...

  2. Effective Java 10 Always override toString() method

    Advantage Provide meaningful of an object info to client. Disadvantage Constrain the ability of chan ...

  3. How to override create,write,unlink method in Odoo v8

    As we all know, Odoo 8 has new api which is different with v7. So how to override the create,write,u ...

  4. 重写Override ToString()方法

    使用一个小例子来演示: 创建一个普通类别: class Ax { private int _ID; public int ID { get { return _ID; } set { _ID = va ...

  5. Java之所有对象的公用方法>10.Always override toString

    providing a good toString implementation makes your class much more pleasant to use. It is recommend ...

  6. override toString() function for TreeNode to output OJ's Binary Tree Serialization

    class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } @Override publ ...

  7. Java重写父类使用@Override时出现The method destroy() of type xxx must override a superclass method的问题解决

    解决方法: 1.把JDK版本改成1.6以上的. 2.把Compiler改成1.6以上的. 关于这两者的区别,参考:http://www.cnblogs.com/EasonJim/p/6741682.h ...

  8. RapidFloatingActionButton框架正式出炉

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4474748.html RapidFloatingActionB ...

  9. Android架构分析之使用自定义硬件抽象层(HAL)模块

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android版本:2.3.7_r1 Linux内核版本:android-goldfish-2.6.29 在上一篇博 ...

随机推荐

  1. Trapping Messages Sent to an Application

    http://www.delphicorner.f9.co.uk/articles/apps7.htm Trapping Messages Sent to an Application I wrote ...

  2. JavaScript创建Map对象(转)

    JavaScript 里面本身没有map对象,用JavaScript的Array来实现Map的数据结构. /* * MAP对象,实现MAP功能 * * 接口: * size()     获取MAP元素 ...

  3. Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和

    B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...

  4. SQL 32位还原位64位出现3154错误

    1:首先检查新建数据库的路径是否正确. 2:勾选覆盖原有数据库. 3:新建查询,选择master.然后新建查询中进行如下直接对bak文件的操作. RESTORE DATABASE TestFROM D ...

  5. Docker:使用Ambassador进行跨主机间容器通信

    转载请注明出处:点我 由于Docker自身的网络的原因,想要在多主机间的容器之间进行通信是比较麻烦的事情.可以利用Ambassador容器来实现这一功能. 基本原理: 利用Ambassador来实现主 ...

  6. OS X下开发!ios系统贪食蛇!——from cocos2d-x 3.0

    前几天用cocos2d-x写了个贪食蛇!这次是全然在osx下开发的.基本的思路是这种我建立了一个Snake类,当中有两个构造函数一个是用于存放蛇身体sprite的图片和Snake的X坐标和Y坐标.另外 ...

  7. oc-32-@property示例

    Goods.h #import <Foundation/Foundation.h> typedef struct{ int year; int month; int day; } MyDa ...

  8. linux查看CPU性能及工作状态的指令

    http://www.aikaiyuan.com/9347.html http://blog.csdn.net/jk110333/article/details/8683478 http://www. ...

  9. xcode中没有autoSizing的设置

    转自:http://blog.sina.com.cn/s/blog_954bb2f001016oyx.html 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原 ...

  10. Disable right click on the website

    Many developers/website owners like to keep their website images personal and don't want anyone to c ...