C# compiler number literals

后端 未结 3 741
误落风尘
误落风尘 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:53

    var y = 0f; // y is single
    var z = 0d; // z is double
    var r = 0m; // r is decimal
    var i = 0U; // i is unsigned int
    var j = 0L; // j is long (note capital L for clarity)
    var k = 0UL; // k is unsigned long (note capital L for clarity)
    

    From the C# specification 2.4.4.2 Integer literals and 2.4.4.3 Real literals. Take note that L and UL are preferred as opposed to their lowercase variants for clarity as recommended by Jon Skeet.

提交回复
热议问题