为什么在System.Delegate上看不到+ =运算符重载? [英] Why don't I see the += operator overloaded on System.Delegate?
问题描述
我看到相等比较运算符 ==
和!=
在 System.Delegate
和 MulticastDelegate
上重载了,但是不是 + =
和-=
运算符.
那么增量分配和减量分配运算符如何在委托实例上工作?
C#编译器将 + =
运算符转换为静态方法 Delegate.Combine
的调用./p>
在很多情况下,编译器会执行此类操作,例如 System.String
的 +
运算符被编译为 String.Concat
调用.因此, System.String
中没有 op_Add
方法.
I see the equality comparison operators ==
and !=
overloaded on System.Delegate
and MulticastDelegate
but not the +=
and -=
operators.
Then how do the increment assign and decrement assign operators work on delegate instances?
The C# compiler translates +=
operator to the call of the static method Delegate.Combine
.
There are several cases when the compiler does such things, f.e. the +
operator of the System.String
is compiled to the String.Concat
call. Therefore there isn't op_Add
method in System.String
.
这篇关于为什么在System.Delegate上看不到+ =运算符重载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!