If value is the keyword in C# and keywords cannot be used as a name (identifier) of a variable, class, interface, etc.

How can value still be used as a variable?

public static void Main(string[] args)
    int value =2;            

1 Answers

Michael Randall On

value is a Contextual Keyword, which means it depends on the context, its not a Reserved Word.

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#.

Here is a list of keywords that are reserved and will need to be prefixed with the @ symbol

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.