Defining different types of numbers in C#(在 C# 中定义不同类型的数字)
问题描述
您可以在 C# 中以多种方式定义数字,
You can define a number in various ways in C#,
1F // a float with the value 1
1L // a long with the value 1
1D // a double with the value 1
我个人正在寻找 short
,但是为了让这个问题成为人们更好的参考,您可以应用哪些其他数字文字的后缀?
personally I'm looking for which would a short
, however to make the question a better reference for people, what are all the other post-fix's to number literals you can apply?
推荐答案
Type Suffix .NET Framework Type
-------------------------------------------------------------------------------------
decimal M or m System.Decimal
double D or d System.Double
float F or f System.Single
int [1] System.Int32
long L or l System.Int64
[1] 当整数文字没有后缀时,它的类型是可以表示其值的类型中的第一个:int、uint、long、ulong.
[1] When an integer literal has no suffix, its type is the first of these types in which its value can be represented: int, uint, long, ulong.
当整数文字仅指定 U 或 u 后缀时,它的类型是这些类型中第一个可以表示其值的类型:uint、ulong.
When an integer literal specifies only a U or u suffix, its type is the first of these types in which its value can be represnted: uint, ulong.
当整数文字仅指定 L 或 l 后缀时,它的类型是这些类型中第一个可以表示其值的类型:long、ulong.
When an integer literal specifies only a L or l suffix, its type is the first of these types in which its value can be represnted: long, ulong.
当整数文字同时指定 U 或 u 和 L 或 l 后缀时,它的类型是这些类型中第一个可以表示其值的类型:ulong.
When an integer literal specifies both a U or u and L or l suffix, its type is the first of these types in which its value can be represnted: ulong.
这篇关于在 C# 中定义不同类型的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中定义不同类型的数字


- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01