Letter after a number, what is it called?

徘徊边缘 提交于 2019-12-18 03:53:31

问题


What is this called?

double  d1 = 0d;
decimal d2 = 0L;
float   d3 = 0f;

And where can I find a reference of characters I can use? If I want to cast 0 to short, which letter I need?


回答1:


The best source is the C# specification (it's in section “2.4.4. Literals” in version 4).

The relevant bits:

The type of an integer literal is determined as follows:

  • If the literal has no suffix, it has the first of these types in which its value can be represented: int, uint, long, ulong.
  • If the literal is suffixed by U or u, it has the first of these types in which its value can be represented: uint, ulong.
  • If the literal is suffixed by L or l, it has the first of these types in which its value can be represented: long, ulong.
  • If the literal is suffixed by UL, Ul, uL, ul, LU, Lu, lU, or lu, it is of type ulong.

If no real-type-suffix is specified, the type of the real literal is double. Otherwise, the real type suffix determines the type of the real literal, as follows:

  • A real literal suffixed by F or f is of type float. […]

  • A real literal suffixed by D or d is of type double. […]

  • A real literal suffixed by M or m is of type decimal. […]

That means the letter (or letters) is called “suffix”. There is no way to represent short this way, so you have to use (short)0, or just short x = 0;.




回答2:


It is called a suffix.
An overview can be found here




回答3:


This

double  d1 = 0d;

is an example of a literal and the character after the digits is a suffix. There is not one for short. You need to cast:

short s = (short)0;

These are defined in 2.4.4 of the language specification, specifically 2.4.4.2 will tell you about integer literals where you will see that there is no way to express a short using a literal. Additionally, the integer-type-suffixes are:

U  u  L  l  UL  Ul  uL  ul  LU  Lu  lU  lu

which represent various signed/unsigned int/long types. Again, no way to express a short using literal.




回答4:


You can find a reference to the literals at the following link:

http://msdn.microsoft.com/en-us/library/aa664672(v=VS.71).aspx

Only the letter after the number is called a suffix.

There is not one specifically for short.

And these are only value literals so that you can differ the different types of values. When you cast you use the regular casting methods.




回答5:


Here's the reference of the decimal type in C#:

http://msdn.microsoft.com/en-us/library/364x0z75(v=VS.100).aspx

And here's the reference of the "Standard Numeric Format Strings", which is what you are asking about:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx



来源:https://stackoverflow.com/questions/6681112/letter-after-a-number-what-is-it-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!