是否可以在C#中重载nameof运算符? [英] Is it possible to overload the nameof operator in c#?

查看:80
本文介绍了是否可以在C#中重载nameof运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在C#中重载nameof运算符吗?

Can I overload the nameof operator in C#?

C#编程指南已过时, C#6在幕后对我没有帮助.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆