操作者+ = [英] operator+=

查看:87
本文介绍了操作者+ =的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为我自己的类定义上面的运算符?我似乎只能定义每一个,除了我想要的那个(总是那样:)


我问的主要原因是事件接口使用Event + = new

EventHandler(..)语法 - 我不确定如何实现它。这是

是通过运营商完成的吗?


我使用的是C#2.0


-

问候,Fil。

Is there any way to define the above operator for my own class? I seem to be
able to define every single one, except the one I want to (always the way :)

The main reason I ask is that the event interfaces use the "Event += new
EventHandler(..)" syntax - I am not sure how this gets implemented. Is this
done via operator+?

I am using C# 2.0

--
Regards, Fil.

推荐答案

Fil Mackay写道:
Fil Mackay wrote:
有没有办法定义我自己上课的上述操作符?我似乎能够定义每一个,除了我想要的那个(总是那样)。

我问的主要原因是事件接口使用Event + =
new EventHandler(..)语法 - 我不确定这是如何实现的。这是通过运营商+来完成的吗?

我正在使用C#2.0
Is there any way to define the above operator for my own class? I
seem to be able to define every single one, except the one I want to
(always the way :)

The main reason I ask is that the event interfaces use the "Event +=
new EventHandler(..)" syntax - I am not sure how this gets
implemented. Is this done via operator+?

I am using C# 2.0




是的,它是+运营商。 :)


FB


-

------------- -------------------------------------------------- ---------

LLBLGen Pro的首席开发人员,.NET的高效O / R映射器

LLBLGen Pro网站: http://www.llblgen.com

我的.NET博客: http://weblogs.asp.net/fbouma

Microsoft MVP( C#)

---------------------------------------- --------------------------------



Yes it''s the + operator. :)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


是,的当然 - 但是操作员+ =通过修改项目内联而不是创建一个新的
实例来为你提供额外的功能来提高效率


不确定你是否知道,但C ++有一个运算符+ =;你不需要用操作符+来攻击它。



问候,Fil。


----- -------------------

Frans Bouma [C#MVP]"写道:
Yes, of course - but the operator+= gives you additional capabilities to
improve efficiency, by modifying the item inline, rather than creating a new
instance

Not sure if you''re aware, but C++ has an operator+=; you dont need to hack
it with operator+.

Regards, Fil.

------------------------
"Frans Bouma [C# MVP]" wrote:
Fil Mackay写道:
Fil Mackay wrote:
有没有办法为我自己的类定义上面的运算符?我似乎能够定义每一个,除了我想要的那个(总是那样)。

我问的主要原因是事件接口使用Event + =
new EventHandler(..)语法 - 我不确定这是如何实现的。这是通过运营商+来完成的吗?

我正在使用C#2.0
Is there any way to define the above operator for my own class? I
seem to be able to define every single one, except the one I want to
(always the way :)

The main reason I ask is that the event interfaces use the "Event +=
new EventHandler(..)" syntax - I am not sure how this gets
implemented. Is this done via operator+?

I am using C# 2.0



是的,它是+运营商。 :)

FB

-
------------------------- -----------------------------------------------
LLBLGen Pro的首席开发人员,这是用于.NET的高效O / R映射器LLBLGen Pro网站: http://www.llblgen.com
我的.NET博客: http://weblogs.asp.net/fbouma
Microsoft MVP(C#)
---------------------- --------------------------------------------------



Yes it''s the + operator. :)

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------



Fil,


1.在c#中,你通过重载+运算符来重载+ =。

2. + =对于事件由C#编译器处理,并且不涉及运算符

重载。有些人可能会对此声明提出异议,但我的意思是

没有生成''op_ *''方法。

-

Stoitcho Goutsev(100)

" Fil Mackay" <网络连接******* @ discussions.microsoft.com>在留言中写道

news:21 ********************************** @ microsof t.com ...
Fil,

1. In c# you overload += by overloading the + operator.
2. += for events is handled by the C# compiler and doesn''t involve operator
overloading. Some may argue with this statement, but what I mean is that
there is no ''op_*'' method generated.
--

Stoitcho Goutsev (100)

"Fil Mackay" <Fi*******@discussions.microsoft.com> wrote in message
news:21**********************************@microsof t.com...
有没有办法为我自己的类定义上面的运算符?我似乎能够定义每一个,除了我想要的那个(总是这样的方式)

我问的主要原因是事件接口使用Event + = new
EventHandler(..)。语法 - 我不确定如何实现它。这是通过运营商来完成的吗?

我正在使用C#2.0

- 问候,Fil。
Is there any way to define the above operator for my own class? I seem to
be
able to define every single one, except the one I want to (always the way
:)

The main reason I ask is that the event interfaces use the "Event += new
EventHandler(..)" syntax - I am not sure how this gets implemented. Is
this
done via operator+?

I am using C# 2.0

--
Regards, Fil.



这篇关于操作者+ =的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆