Alex Rivera | Logout

C# compiler number literals

Asked 2008-10-03T13:09:27.737
39

Does anyone know the full list of C# compiler number literal modifiers?

By default declaring '0' makes it an Int32 and '0.0' makes it a 'Double'. I can use the literal modifier 'f' at the end to ensure something is treated as a 'Single' instead. For example like this...

var x = 0;    // x is Int32
var y = 0f;   // y is Single

What are the other modifiers I can use? Is there one for forcing to Double, Decimal, UInt32? I tried googling for this but could not find anything. Maybe my terminology is wrong and so that explains why I am coming up blank. Any help much appreciated.

Edit
Report

1 Answer

5

You might want to start by looking at the C# language spec. Most of the types are listed in there, and have a suffix:

  • L = long
  • F = float
  • U = uint
  • ulong's are a little different
  • m = decimal (money)
  • D = double

Of course, if you stop using var then you get around the whole problem, and your code becomes more readable (ok, that's subjective, but for something like this, it's more readable by other people):

var x = 0; //whats x?
float x = 0; //oh, it's a float
byte x = 0; // or not!
answered 2008-10-03T13:17:03.057

Your Answer