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

推荐订阅源

博客园 - 叶小钗
D
Docker
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
博客园 - 【当耐特】
N
Netflix TechBlog - Medium
V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Recent Announcements
Recent Announcements
GbyAI
GbyAI
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
L
LangChain Blog
A
About on SuperTechFans
M
MIT News - Artificial intelligence
B
Blog

博客园 - 点点滴滴

C#操作IIS的代码 恢复误删数据(SQL Server 2000)--Log Explorer 如何让ClickOnce进行手动更新(含代码) - 点点滴滴 - 博客园 BackgroundWorker 组件 获取VS.NET 自带的数据库连接对话框的数据库连接 搜索一个局域网中所有的SQL Server服务器 Application.DoEvent() 在C#使用XML注释 用IDisposable接口释放.NET资源 很好的debug有理由不用吗 C#调用API访问其它进程 抽象 虚方法 接口 的区别 ASP.NET AJAX 路线图 ASP.NET AJAX 概述 安装ASP.NET AJAX Visitor Template Method Strategy State
正确的重载operator
点点滴滴 · 2006-12-16 · via 博客园 - 点点滴滴

           用户定义类型选择正确的重载operator+的一般性处理例如我们在赋值语句中经常使用 a+=1 ; b-=2; c*=3; d/=3;  如果x和y是用户定义的类型, 就不能确保这样。
        代码如下 :

 1   public class Saver : IDisposable
 2    {
 3        // Fields
 4        private TextBox m_textBox;
 5
 6        private int m_start, m_end;
 7
 8        /// <summary>
 9        ///   Initializes a new instance of the Saver class by associating it with a TextBoxBase derived object. </summary>
10        /// <param name="textBox">
11        ///   The TextBoxBase object for which the selection is being saved. </param>
12        /// <remarks>
13        ///   This constructor saves the textbox's start and end position of the selection inside private fields. </remarks>
14        /// <seealso cref="System.Windows.Forms.TextBoxBase" />    

15        public Saver(TextBox textBox)
16        {
17            m_textBox = textBox;
18        }

19
20        public static Saver operator +(Saver saver, int pos)
21        {
22            return new Saver(saver.m_textBox, saver.m_start + pos, saver.m_end + pos);
23        }

24
25        public void MoveBy(int start, int end)
26        {
27            m_start += start;
28            m_end += end;
29
30            Debug.Assert(m_start <= m_end);
31        }

32    }

33