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 在上一篇博 ...
随机推荐
- dmalloc 原文 翻译整理
http://blog.csdn.net/cardinal_508/article/details/5553387 L13 从快速入门开始(Quickstart) 这个库是一个文件中所有简化用法中最常 ...
- DAG成员服务器还原
DAG成员服务器 exmb02 已损坏: 1.使用 Get-MailboxDatabase cmdlet 为要恢复的服务器上的任何邮箱数据库副本检索所有重播延迟和截断延迟设置: Get-Mailb ...
- boost::token_compress_on
对于场景:string s = "123456",用"3","4"切分,默认情况下(boost::token_compress_off),切 ...
- GLSL实现Interactive Fluid 流体【转】
http://blog.csdn.net/a3070173/archive/2008/12/08/3479477.aspx 完成的部分: 1.流体本身的绘制和更新 未解决的部分: 1.由于采用经过抖动 ...
- Android Studio下载安装使用教程
最近Google的在Google I/O大会上推出了一款新的开发工具android studio.这是一款基于intellij IDE的开发工具,使用Gradle构建,相信做过java的童鞋们都知道这 ...
- [CSS] Introduction to CSS Columns
Learn how to use CSS columns to quickly lay out fluid columns that are responsive, degrade gracefull ...
- linux用户权限
Linux下passwd和shadow文件内容详解 一./etc/passwd/etc/passwd 文件是一个纯文本文件,每行采用了相同的格式: name:password:uid:gid:comm ...
- eclipse的scala环境搭建
两种方法使eclipse安装scala环境(eclipse luna) 1.下载eclipse for scala IDE http://scala-ide.org/download/sdk.html ...
- .Net Static 与单例
Static 关键字作为修饰符可以用于类.方法和成员变量上.其含义是对于整个应用程序生命周期内,访问该修饰符修饰的对象/方法/变量都引用到同一实例(内存地址).但正因如此在多线程下会出现线程安全问题: ...
- C小加 之 随机数
描述ACM队的“C小加”同学想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(0<N≤100),对于其中重复的数字,只保留一个,把其余相 ...