C# – What does the word “literal” mean

cglossarylanguage-agnosticterminology

What does the word "literal" mean when used in context such as literal strings and literal values?

What is the difference between a literal value and a value?

Best Answer

A literal is "any notation for representing a value within source code" (wikipedia)

(Contrast this with identifiers, which refer to a value in memory.)

Examples:

  • "hey" (a string)
  • false (a boolean)
  • 3.14 (a real number)
  • [1,2,3] (a list of numbers)
  • (x) => x*x (a function)
  • /^1?$|^(11+?)\1+$/ (a regexp)

Some things that are not literals:

  • std::cout (an identifier)
  • foo = 0; (a statement)
  • 1+2 (an expression)