Is nameof() evaluated at compile-time?
问题 In C# 6, you can use the nameof() operator to get a string containing the name of a variable or a type. Is this evaluated at compile-time, or at runtime via some Roslyn API? 回答1: Yes. nameof() is evaluated at compile-time. Looking at the latest version of the specs: 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