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

推荐订阅源

Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
B
Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
爱范儿
爱范儿
博客园_首页
博客园 - 聂微东
量子位
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
The Cloudflare Blog
T
Tailwind CSS Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC

博客园 - 点点滴滴

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