简体   繁体   English

是否有可能在c#中重载nameof运算符?

[英]Is it possible to overload the nameof operator in c#?

Can I overload the nameof operator in C#? 我可以在C#中重载nameof运算符吗?

The C# programming guide is outdated and the C# 6 under the hood doesn't help me. C#编程指南已经过时, 引擎盖下的C#6对我没有帮助。

How can I overload the nameof operator? 如何重载nameof运算符?

The nameof operator is evaluated at compile-time. nameof运算符在编译时进行评估。

The nameof expression is a constant. 表达式的名称是常量。 In all cases, nameof(...) is evaluated at compile-time to produce a string. 在所有情况下,在编译时评估nameof(...)以生成字符串。 Its argument is not evaluated at runtime, and is considered unreachable code (however it does not emit an "unreachable code" warning). 它的参数不在运行时进行评估,并且被认为是无法访问的代码(但它不会发出“无法访问的代码”警告)。

So, these operator cannot be overloaded. 所以,这些运算符不能超载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM