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. 广州项目实施步骤I_练习安装 CentOS x64 6.4

    安装Centos x64 6.4 在家里使用 Vmware10.0.1进行模拟安装. 永久KEY注册密钥:5F29M-48312-8ZDF9-A8A5K-2AM0Z  下载地址:http://pan. ...

  2. ASP.NET方面的一些经典文章收集

    1. 在ASP.NET中执行URL重写 文章地址:https://msdn.microsoft.com/zh-cn/library/ms972974.aspx 2. 在ASP.NET中如何实现和利用U ...

  3. QoS 测量 (目标,方法,协议)

    本文翻译自ITU-T的Technical Paper:<How to increase QoS/QoE of IP-based platform(s) to regionally agreed ...

  4. 基于Raft构建弹性伸缩的存储系统的一些实践

    基于Raft构建弹性伸缩的存储系统的一些实践 原创 2016-07-18 黄东旭 聊聊架构 最近几年来,越来越多的文章介绍了 Raft 或者 Paxos 这样的分布式一致性算法,但主要集中在算法细节和 ...

  5. 《linux性能及调优指南》

    http://blog.chinaunix.net/uid-26000296-id-4065871.html

  6. Linux合并文件、去除重复行的命令

    Linux合并文件命令: awk '{printf("%s\n",$0)}' YQ-*101?.txt >  123.txt   linux去除重复行命令:cat YQ-10 ...

  7. 用iDSDT制作声显卡DSDT

    已有 2299 次阅读2011-10-24 21:00 |个人分类:Mac| DSDT 快速增加积分秘笈! windows下!--------------------------------第一步.下 ...

  8. 项目源码--Android即时通讯IM客户端

    下载源码   技术要点: 1.完整精美客户端UI设计 2.自定义控件的灵活使用 3.UI控件的详细使用 4.即时通讯IM协议的实现 5.完整即时通讯IM客户端实现 6.源码详细的中文注释 …….   ...

  9. cocos2dx3.0-执行cocos compile -p win32 命令出现错误 MSB8020 以及编译出来的exe 无法打开的问题

    本文由@呆代待殆原创,转载请注明出处:http://www.cnblogs.com/coffeeSS/ 当博主准备把cocos工程用cocos命令行编译出来的时候,报出了MSB8020的错误,具体如下 ...

  10. C Struct Hack

    It's not clear if it's legal or portable, but it is rather popular. #include <stdlib.h> #inclu ...