C# compiler number literals

后端 未结 3 748
误落风尘
误落风尘 2020-11-30 02:54

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

3条回答
  •  鱼传尺愫
    2020-11-30 03:33

    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, thats 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!
    

提交回复
热议问题