<分区>
如果value
是C# 中的关键字 并且关键字 不能用作名称( 变量、类、接口(interface)等的标识符。
value
如何仍然用作变量?
public static void Main(string[] args)
{
int value =2;
Console.WriteLine(value);
}
标签 c#
<分区>
如果value
是C# 中的关键字 并且关键字 不能用作名称( 变量、类、接口(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 wordvalue
references the value that client code is attempting to assign to the property.
A contextual keyword is used to provide a specific meaning in the code, but it is not a reserved word in C#.
这是保留的关键字列表,需要使用 @
符号作为前缀
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, butif
is not because if is a keyword.
关于c# - 为什么 'value' 可以用作变量,而它是 C# 中的关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55885963/