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# 中定义不同类型的数字


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01