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. Thread message loop for a thread with a hidden window? Make AllocateHwnd safe

    Thread message loop for a thread with a hidden window? I have a Delphi 6 application that has a thre ...

  2. ARM&Linux 下驱动开发第二节

    驱动文件:qudong.c,make生成qudong.ko文件,烧录到ARM板上 #include<linux/init.h> #include<linux/module.h> ...

  3. 苹果iOS手机暗藏间谍软件的揭秘者:扎徳尔斯基

    大家知道,苹果iOS手机的短消息server(SMS)是用硬件加密的,看起来非常安全.可是,Jonathan Zdziarski发现苹果公司有意地放进去一个"文件转发server" ...

  4. Android Widget 小部件(三) 在Activity中加入Widget

    package com.stone.ui; import static android.util.Log.d; import android.app.Activity; import android. ...

  5. 判断浏览器是否IE10

    项目中做打印预览时,在IE10中出现兼容性问题,需要针对IE10做特殊处理. 在网上搜了一下,有三种方法可以实现 一.特性检测:@cc_on <!--[if !IE]><!--> ...

  6. MySQL Order By实现原理分析和Filesort优化

    http://blog.csdn.net/hguisu/article/category/796963

  7. 关于c#调用c/c++ dll遇到的问题总结

    前段时间公司做了个winform程序,需要调用c 的dll去读取卡号的程序,期间遇到些问题,下面来分享下 一.dll路径问题 相信很多开发者都会遇到这个问题,我总结了下我现在有3总方式去解决这个问题: ...

  8. Linux下redis安装与使用

         redis官网地址:http://www.redis.io/      最新版本:2.8.3      在Linux下安装Redis非常简单,具体步骤如下(官网有说明):      1.下载 ...

  9. Good subsequence( RMQ+二分)

    Description Give you a sequence of n numbers, and a number k you should find the max length of Good ...

  10. Ultra Edit常用正则表达式

    一.怎样可以删除包含特殊字符的行? 你可以用正则表示式全部替换命令替换行中包含的字符.要执行这个操作,你应该先进行查找: 查找: %*YOUR STRING*^p 替换为: (随便什么文字) 帮助文件 ...