[英]What is the difference between f and F
In the following code, the const are defined using two different ways. 在以下代码中,const使用两种不同的方式定义。
const float KS = 0.001F;
const float WW = 0.001f;
Is there any difference between F and f? F和f之间有什么区别吗?
Revision 1: If both are same then why both cases are allowed ? 修订版1:如果两者相同,为什么允许两种情况?
Nope, no difference between f
and F
in this case. 不,在这种情况下,
f
和F
之间没有区别。 It's the special suffix for float
literals, either works fine. 它是
float
文字的特殊后缀,可以正常工作。
With the long
literals, there's stylistic difference: l
(lowercase) looks a lot like 1
(the number one). 随着
long
文字,有风格差异: l
(小写)看起来很像1
(第一)。 It's recommended to use capital L
for long
literals. 建议使用大写
L
来表示long
文字。
MSDN/C# Programmer's Reference/float MSDN / C#程序员参考/浮点数
By default, a real numeric literal on the right-hand side of the assignment operator is treated as
double
.默认情况下,赋值运算符右侧的实数数字文字被视为
double
。 Therefore, to initialize a float variable use the suffixf
orF
.因此,要初始化float变量,请使用后缀
f
或F
MSDN/C# Programmer's Reference/long MSDN / C#程序员参考/长
You can also use the lowercase letter
"l"
as a suffix.您也可以使用小写字母
"l"
作为后缀。 However, this generates a compiler warning because the letter"l"
is easily confused with the digit"1"
.但是,这会生成编译器警告,因为字母
"l"
很容易与数字"1"
混淆。 Use"L"
for clarity.为清楚起见,请使用
"L"
。
Yes, the case :) Functionality wise, no. 是的,案例:)功能明智,没有。 Its the same as
String
and string
. 它与
String
和string
相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.