Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between f and F

Tags:

c#

.net

In the following code, the const are defined using two different ways.

     const float KS = 0.001F;
     const float WW = 0.001f;

Is there any difference between F and f?

Revision 1: If both are same then why both cases are allowed ?

like image 899
Ram Avatar asked May 30 '10 12:05

Ram


1 Answers

Nope, no difference between f and F in this case. It's the special suffix for float literals, either works fine.

With the long literals, there's stylistic difference: l (lowercase) looks a lot like 1 (the number one). It's recommended to use capital L for long literals.

References

  • MSDN/C# Programmer's Reference/float

    By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. Therefore, to initialize a float variable use the suffix f or F.

  • MSDN/C# Programmer's Reference/long

    You can also use the lowercase letter "l" as a suffix. However, this generates a compiler warning because the letter "l" is easily confused with the digit "1". Use "L" for clarity.

like image 164
polygenelubricants Avatar answered Oct 02 '22 16:10

polygenelubricants