Testing

Why is a data type suffix required?

The data type suffix helps the compiler to unambiguously identify the data type of any value/literal. It also helps C# programmer to explicitly state the data type of the value/literal.

In the cases when a variable is declared, using one of the “var”, “dynamic” or “object” keywords, use the data type suffix to explicitly state the data type of the value.

In case of integer literals, if you don't specify any suffix, then the integer values are evaluated to a data type, as per the sequence given below.

  • int
  • uint
  • long
  • ulong

In case of real- value literals (those with decimal points or fractions e.g. 3.14), if you don't specify any suffix, then a real- value literal is evaluated to a data type, as per the sequence given below.

  • double
  • float/decimal (based on suffix)

In short, without any data type suffix, an integer literal will be evaluated to int and real literal will be evaluated to double.

There are data type suffixes given below.

  • L or l for long
    • (l in small letters should be avoided as it confuses you with digit 1)
  • D or d for double
  • F or f for float
  • M or m for decimal
    • (D is already taken for double, so M is best representation for decimal)
  • U or u for unsigned integer
  • UL or ul for unsigned long