C# Literals

Literals are value constants assigned to variables in a program. In C#, there are 6 types of literals are exists.

  • Integer Literals
  • Real Literals
  • Boolean Literals
  • Single Character Literals
  • String Literals
  • Backslash Character Literals
  • c# literals

    Integer Literals:

    An Integer Literals refers to a sequence of digits. There are two types of integer namely:

  • Decimal Integers
  • Hexamdecimal Integers
  • Decimal Integers:

    Decimal Integers cosists of a set of digits, o to 9 preceded by an optional minus sign.

    123, -321, 654321

    Hexamdecimal Integers:

    Hexamdecimal Integers refers to a sequence of digits preceded by 0x or 0X is considered as a Hexamdecimal Integers. It may also include alphabets A, B, C, D, E, F or a, b, c, d, e, f.

  • A or a represents the number 10
  • B or b represents the number 11
  • C or c represents the number 12
  • D or d represents the number 13
  • E or e represents the number 14
  • F or f represents the number 15
  • Example:

    0x, 0X2, 0X9F, 0Xbcd