是否可以在C#中重载nameof运算符? [英] Is it possible to overload the nameof operator in c#?
本文介绍了是否可以在C#中重载nameof运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在C#中重载nameof
运算符吗?
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.
如何重载nameof
运算符?
推荐答案
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. 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.
这篇关于是否可以在C#中重载nameof运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文