为什么在System.Delegate上看不到+ =运算符重载? [英] Why don't I see the += operator overloaded on System.Delegate?

查看:58
本文介绍了为什么在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屋!

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