by Michael S. Kaplan, published on 2008/07/28 05:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2008/07/28/8782341.aspx
I was asked the other day for some help understanding why the letters used in C# to determine different kinds of literals were not the same as the letters used for format specifiers.
Hmmmmm, interesting. First let's look at what they are.
For format specifiers (from the Standard Numeric Format Strings topic):
Now the important note here is that we are looking at hints for how to deal with numbers that are contained within strings -- like the character to use in a ToString() call.
The type of the number being converted to a string is not needed here -- it is implicit in the type it is already in! After all, if I call Decimal.ToString() then I know the type is Decimal.
Also, if you look at the topic you will see that each of these types has a specific meaning. One could argue that the definition of the "Decimal" format specifier might lead to confusion given the Decimal type, but that is a separate issue. :-)
In the end, this is a hint to a way to format a string at runtime.
Now the literal specifier is for a different purpose.
Its intention is to give a hint on how to treat a literal number o how it is represented in the compiled code is what would be expected. The number will always have a specific representation in the code, and the suffixes can be used to override that default. The suffixes are similar to generally but quite different from specifically in their values, e.g.:
and so on.
Something very different is being done with these suffixes, which is why the two groups are slightly different anyway -- they don't really overlap, and the meanings change like in the Decimal example I mentioned above.
A little confusing, perhaps. But when one really thinks about the whole situation, it all kind of makes sense....
Now when you add on the concept of localization (you knew I'd be doing that eventually!), neither of these are localized, but obviously the descriptions will be.
Thus if you look at the French equivalent of the English Standard Numeric Format Strings and find in Chaînes de format numériques standard the fact that the format specifier stays the same as even the name changes is obvious....
This blog brought to you by m (U+006d, aka LATIN SMALL LETTER M)
go to newer or older post, or back to index or month or day