#20 – Literals

A literal in C# is a representation, in your source code, of a constant value.  You can use literals when assigning a value to a variable, when passing a parameter value to a method, or wherever a variable of the corresponding type is expected.

C# defines six different types of literals:

  • Boolean literal:  true | false
  • Integer literal:  e.g. 12, 24L, 100UL, 0x7DC
  • Real literal:  e.g. 1.0, 2.2F, 4, 6.02E23, 123.45m
  • Character literal:  e.g. ‘a’, ‘Z’, ‘#’, ‘\n’, ‘\”, ‘\\’, ‘\x45’, ‘\x04DA’
  • String literal: e.g. “Sean”, @”Print\nMe”, “Look: \x04DA”, “Look: Ӛ”, “Line 1\nLine 2”
  • Null literal:  null