C# Numeric Literals Suffixes

The suffixes in the table below are useful because they tell the compiler what type a numeric literal is and how it should be treated. The default type of a numeric literal is integer (int) of course, but if you want to specify decimal or long, how would you do that? (please don’t cast it, it’s ugly)

Consider having an overloaded method, one overload takes a parameter of type long, another of type int, now if you want to pass in the number ’15′ for example, these suffixes will help you choose which overload to actually invoke by appending a letter (or two) to the numeric literal.

Type   Suffix   Example
  uint   U or u   100U
  long   L or l   100L
  ulong   UL or ul   100UL
  float   F or f   123.45F
  decimal   M or m   123.45M

Note that the suffixes are case-insensitive.

2 Comments

  1. Abraham Luna
    Posted June 13, 2008 at 2:08 PM | Permalink

    Is there a suffix for shorts?

  2. Posted June 16, 2008 at 10:03 AM | Permalink

    Not that I know of.
    I’m not sure why though.


Post a Comment

Required fields are marked *

*
*