在 C# 中定义不同类型的数字

Defining different types of numbers in C#(在 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# 中定义不同类型的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)