tags:

views:

108

answers:

2

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 ?

+12  A: 

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.

polygenelubricants
If both are same then why both cases are allowed ?
Ram
@Ram: Why not???
polygenelubricants
It may create confusion. As string and String are also same. I was just wondering why both are allowed. Microsoft can restrict developer to use only a single one.
Ram
A: 

Yes, the case :) Functionality wise, no. Its the same as String and string.

James
If both are same then why both cases are allowed ?
Ram
It is just an alias. I tend to use it to differ between referring to an object or the type itself i.e if I am using a static method of string I would always do `String.IsNullOrEmpty` never `string.IsNullOrEmpty` purely my own style as I think it looks neater. On the other hand I don't tend to do `String str = "test"` I always do `string str = "test"`. It may also be for people porting from Java as the case was always `String`.
James