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

推荐订阅源

S
Security @ Cisco Blogs
罗磊的独立博客
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
美团技术团队
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
G
Google Developers Blog
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
Visual Studio Blog
腾讯CDC
S
SegmentFault 最新的问题
Recent Announcements
Recent Announcements
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
雷峰网
雷峰网
L
LangChain Blog
Vercel News
Vercel News
Forbes - Security
Forbes - Security
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
S
Security Affairs
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
J
Java Code Geeks
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
Schneier on Security
Schneier on Security
A
About on SuperTechFans
Attack and Defense Labs
Attack and Defense Labs
Google Online Security Blog
Google Online Security Blog
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
B
Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic

博客园 - 修多

mac环境下无法更新OFFICE时,可以直接下载离线升级包 AxureRP_for_chorme的安装和使用方法 解决国内gem不能用的问题 ASP操作Word的权限配置 北京天天有雨下 项目记事 声声慢-李清照 荷兰风车 要继续消失了 孤独的要窒息 消失归来 新疆帕米尔高原 长白山天池 人生的几个好习惯[转载] 今天的心情本来很好 涅槃后方能重生 为心中理想奋斗! 心态决定着今天! 从郁闷到爽,真是够爽的! 昨晚睡得较早,今早精神爽啊 联想“精神病”,文摘 3.29-4.10安排 Windows Server 2003环境下安装JBuilderX 十八个故事[转载]—值得一看 接口实现的继承机制 属性重载的简单说明 索引指示器 static readonly与使用const的区别
操作符重载
修多 · 2004-03-22 · via 博客园 - 修多

C#中,下列操作符可以重载:
+ - ! ~ ++ 00 true false
* / % & | ^ << >> == != > < >= <=
下列操作符是不允许进行重载的:
= && || ?: new typeof sizeof is

// 操作符重载演示
using System;
class Player
{
    public int neili;
    public int tili;
    public int jingyan;
    public int neili_r;
    public int tili_r;
    public Player()
    {
        neili = 10;
        tili = 50;
        jingyan = 0;
        neili_r = 50;
        tili_r = 50;
    }
   
    // 一元操作符重载
    public static Player operator ++(Player p)
    {
        p.neili = p.neili + 50;
        p.tili = p.tili + 50;
        p.neili_r = p.neili;
        p.tili_r = p.tili;
        return p;
    }
   
    // 二元操作符重载
    public static Player operator +(Player p1, Player p2)
    {
        Player p = new Player();
        p.neili = p1.neili +p2.neili;
        p.tili = p1.tili + p2.tili;
        p.neili_r = p.neili;
        p.tili_r = p.tili;
       
        return p;
    }
   
    public static void Main()
    {
        Player p1 = new Player();
        Player p2 = new Player();
        p1++;
        Console.WriteLine(" {0}", p1.neili);
       
        Player p = p1 + p2;
        Console.WriteLine(" {0}", p.neili);
    }
}