c# - 为什么 'value' 可以用作变量,而它是 C# 中的关键字?

标签 c#

<分区>

如果valueC# 中的关键字 并且关键字 不能用作名称( 变量接口(interface)等的标识符

value 如何仍然用作变量?

public static void Main(string[] args)
{
    int value =2;            
    Console.WriteLine(value);       
}

最佳答案

value上下文关键字,这意味着它取决于上下文,它不是保留字

The contextual keyword value is used in the set accessor in ordinary property declarations. It is similar to an input parameter on a method. The word value references the value that client code is attempting to assign to the property.

Contextual Keywords

A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#.

这是保留的关键字列表,需要使用 @ 符号作为前缀

C# Keywords

Keywords are predefined, reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a valid identifier, but if is not because if is a keyword.

关于c# - 为什么 'value' 可以用作变量,而它是 C# 中的关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55885963/

相关文章:

c# - 使用SniffingConnectionPool时出现Nest 2.4.6错误

c# - Entity Framework 4 : Problem with ForeignKey when removing a child entity from parents collection

c# - 使用相同方法自定义用户控件,以相同的方式调用它们

c# - EntityFramework where 子句是否始终按相同顺序返回对象

c# - 如何在更改领域事件结构后检索历史事件

c# - 如何在新页面上打开 ListView 项目

c# - 如何隐藏 Windows Mobile 6.5 中的小键盘弹出窗口? (C#)

c# - 单击浏览按钮后无法访问 Windows 文件夹

c# - 如何在不实例化对象或没有静态方法的情况下获取类的名称?

C# Blank else 如果不好的做法要转义?