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

陌路散爱 提交于 2019-12-10 19:40:43

问题


Can I overload the nameof operator in C#?

The C# programming guide is outdated and the C# 6 under the hood doesn't help me.

How can I overload the nameof operator?


回答1:


The nameof operator is evaluated at compile-time.

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).

So, these operator cannot be overloaded.



来源:https://stackoverflow.com/questions/47811561/is-it-possible-to-overload-the-nameof-operator-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!