c# - 是否可以在 C# 中重载 nameof 运算符?

标签 c# operator-overloading c#-6.0

我可以在 C# 中重载 nameof 运算符吗?

C# programming guide已经过时并且 C# 6 under the hood对我没有帮助。

如何重载 nameof 运算符?

最佳答案

nameof 运算符在编译时求值。

The nameof expression is a constant. In all cases, nameof(...) is evaluated at compile-time to produce a string. Its argument is not evaluated at runtime, and is considered unreachable code (however it does not emit an "unreachable code" warning).

因此,这些运算符不能被重载。

关于c# - 是否可以在 C# 中重载 nameof 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47811561/

相关文章:

c# - 从 DateTime 列中为每一天选择最小时间值

c# - 高效声明/创建变量/控件

c++ - enable_if 类型不属于某个模板类

c++ - 免费运营商与成员(member)运营商

c# - 使用字符串格式格式化小数

c# - 使用空传播时出现 NullReferenceException

c# - 如何通过 .Net Web 服务使用相同的域实体?

c# - Observable.Interval 等待 Action 完成

c++ - C++ 的 operator[] 可以接受多个参数吗?

c# - 不同类型的只读属性