问题
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