惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - 拼命郎

Gated Check-in function in TeamBuild 2010 关于asp.net2.0里的Multiview和View控件的显示与隐藏实现的问题 急死我了!!!vs 2005 单元测试 总是报错 读书笔记- programing .net components(o'Reilly) 由一个关于数据库操作类的写法而想到的。。。。 在sqlserver建表时尽量不要用特殊的字符,如[、]、回车等 关于嵌套事务的一种处理方法 - 拼命郎 关于.net 控件的html 属性的几点技巧 一个关于内容换行的问题 - 拼命郎 jbuilder 中不能调试的一种情况 几点关于java的代码常用规范 最近项目中一些关于代码编写管理的一些思考 几点asp.net的小收获 IsDbNull 方法的用法 两个概念:结构化和层次化的含义 一个char类型的字符赋给一个string对象时不会发生装箱操作 浅析.Net下的AppDomain编程 (转载) 属性(Attributs)笔记 用事件和代理实现的一个闹钟实例
操作符重载笔记
拼命郎 · 2006-01-12 · via 博客园 - 拼命郎

首先概述重载方法:
1.首先指定访问修饰符。public  private
2.关键字 使该操作符成为类的公共操作符,而不是特定对象的操作符.这是强制关键字  static
3.定义操作符的返回类型.返回类型是操作符的结果所使用的类型. 即要得到的计算结果类型
4.在返回类型之后,指定关键字,该关键字必须在被重载的操作符之前指定.这是强制关键字 operator
5.然后必须指定被重载的操作符.(只能重载简单操作符,不能重载符合操作符)
6.最后,必须指定该操作符执行运算时所用的参数.一般两个
几种常见的操作符重载:
传统的操作符必须成对重载:
< and >
<= and >=
== and !=
Override the Equals method if overloading == and !=
Override the GetHashCode method if overriding equals method
(这是老师给的英文,下面我的翻译不能保证正确)
如果重载了 == and != 那么同时也重载了 Equals 方法。
如果重载了equals 方法,那么同时也重载了GetHashCode 方法。
对逻辑操作符的重载:
操作符 && 和 || 不能被直接重载。
他们是符合操作符,在 &, |, true, and false 被重载后,他们也同时被重载。
x && y 这样重载 T.false(x) ? x : T.&(x, y)
x || y 这样重载 T.true(x) ? x : T.|(x, y)
对转换操作符重载:
public static explicit operator Time (float hours)
{ ... }
public static explicit operator float (Time t1)
{ ... }
public static implicit operator string (Time t1)
{ ... }
还可以对操作符进行多次重载,只要参数不同或返回值不同就可以,如:
public static Time operator+(Time t1, int hours)
{...}

public static Time operator+(Time t1, float hours)
{...}

public static Time operator-(Time t1, int hours)
{...}

public static Time operator-(Time t1, float hours)
{...}