Part 57 to 58 Why should you override ToString and Equal Method
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的更多相关文章
- C#中 ToString 和 override ToString 的区别
public class p { public string ToString(){ return "p"; } } public class c:p{ public string ...
- Effective Java 10 Always override toString() method
Advantage Provide meaningful of an object info to client. Disadvantage Constrain the ability of chan ...
- 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 ...
- 重写Override ToString()方法
使用一个小例子来演示: 创建一个普通类别: class Ax { private int _ID; public int ID { get { return _ID; } set { _ID = va ...
- Java之所有对象的公用方法>10.Always override toString
providing a good toString implementation makes your class much more pleasant to use. It is recommend ...
- 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 ...
- 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 ...
- RapidFloatingActionButton框架正式出炉
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4474748.html RapidFloatingActionB ...
- Android架构分析之使用自定义硬件抽象层(HAL)模块
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Android版本:2.3.7_r1 Linux内核版本:android-goldfish-2.6.29 在上一篇博 ...
随机推荐
- ASSER、VERIFY、TRACE详解
ASSERT()被测试它的参数,如果参数为零,则中断执行并打印一段说明消息.在Release版本的程序中它不起任何作用. ASSERT()使用的时候必须保证参数表达式中不能有函数调用,因此对于任何有函 ...
- 可配置多功能门 SN74LVC1G57, 1G58, 1G97, 1G98, 1G99
Configurable Multiple-Function Gate SN74LVC1G57 SN74LVC1G58 SN74LVC1G97 SN74LVC1G98 SN74LVC1G99
- hadoop学习笔记之倒排索引
开发工具:eclipse 目标:对下面文档phone_numbers进行倒排索引: 13599999999 1008613899999999 12013944444444 13800138000137 ...
- 深入研究Clang(三) libclang
作者:史宁宁 如今的Clang,不不过一个编译器前端,同一时候也能够作为一个库使用.作为一个库使用的时候,能够用它去分析C/C++/ObjectC语言代码,能够分析源代码得到AST,也能够获取已经分析 ...
- CSS样式如何解决IE浏览器不同版本的兼容问题
如果你想让浏览器是固定的IE6版本,那么你做网页的时候在<head>后面加上一句话: <meta http-equiv="X-UA-Compatible" con ...
- js正則表達式语法
1. 正則表達式规则 1.1 普通字符 字母.数字.汉字.下划线.以及后边章节中没有特殊定义的标点符号,都是"普通字符".表达式中的普通字符,在匹配一个字符串的时候,匹配与之同样的 ...
- 开机就提示“请安装TCP/IP协议,error=10106”的解决的方法
一.问题描写叙述: 今天开机时提示"请安装TCP/IP协议,error=10106",现象是popo,qq等登录不了,IE浏览器等连不了网,使用ping命令ping其它机器和路由器 ...
- initrd映像文档的作用和制作
1.http://pan.baidu.com/s/1dDrGeKL 2.http://wenku.baidu.com/link?url=qPa_jfkEZCbERnwMYWLwm9EZJ_ebMRJA ...
- 分治法(一)(zt)
这篇文章将讨论: 1) 分治策略的思想和理论 2) 几个分治策略的例子:合并排序,快速排序,折半查找,二叉遍历树及其相关特性. 说明:这几个例子在前面都写过了,这里又拿出来,从算法设计的策略的角度把它 ...
- Docker 选项和命令
选项 -D=true|false 使用 debug 模式.默认为 false. -H, --host=[unix:///var/run/docker.sock]: tcp://[host:port]来 ...