C# compiler number literals(C# 编译器数字文字)
问题描述
有人知道 C# 编译器数字文字修饰符的完整列表吗?
默认情况下,声明 '0' 使其成为 Int32 和 '0.0' 使其成为 'Double'.我可以在末尾使用文字修饰符f"来确保将某些内容视为单一".比如像这样……
var x = 0;//x 是 Int32变量 y = 0f;//y 是单一的我可以使用哪些其他修饰符?是否有一个强制加倍,十进制,UInt32?我试着用谷歌搜索,但找不到任何东西.也许我的术语是错误的,所以这解释了为什么我会出现空白.非常感谢任何帮助.
var y = 0f;//y 是单一的变量 z = 0d;//z 是双倍的变量 r = 0m;//r 是十进制变量 i = 0U;//i 是无符号整数变量 j = 0L;//j 很长(为清楚起见,请注意大写 L)变量 k = 0UL;//k 是无符号长整数(为清楚起见,请注意大写 L)来自 C# 规范 2.4.4.2 整数文字和 2.4.4.3 实数.请注意,Jon Skeet 推荐的 L 和 UL 是首选,而不是小写变体.p>
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.
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.
这篇关于C# 编译器数字文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 编译器数字文字
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
