views:

1038

answers:

4

Good Day,

In order to work with decimal data types, I have to do this with variable initialization:

decimal aValue = 50.0M;

What does the M part stand for?

coson

A: 

Probably stands for Money.

mquander
+4  A: 

See this (written by our own Jon Skeet):
http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88466.aspx

and this (more detail):
http://www.blackwasp.co.uk/CSharpNumericLiterals.aspx

Joel Coehoorn
+2  A: 

M means decimal. If you don't add it the number will be treated as a double. D is double.

MDStephens
"M", like in "decimal" :)
VVS
I suppose there is some important reason, but it irritates me that you get a compile-time error if you leave the m out of the literal. It's not as if it's ambiguous.
SeaDrive
+7  A: 

It means it's a decimal literal, as others have said. However, the origins are probably not those suggested elsewhere in this answer. From the C# Annotated Standard (the ECMA version, not the MS version):

The decimal suffix is M/m since D/d was already taken by double. Although it has been suggested that M stands for money, Peter Golde recalls that M was chosen simply as the next best letter in decimal.

A similar annotation mentions that early versions of C# included "Y" and "S" for byte and short literals respectively. They were dropped on the grounds of note being useful very often.

Jon Skeet
That leaves the question why E/e was not the next best letter.
VVS
"e" would be problematic in that it's already used in literals. For instance "2e4m" is a valid literal (decimal 20000). Even if it were unambiguous (and it may well be, although "1e" ends up with a curious compiler error message suggesting it's out of the range of viable doubles, not that it's syntactically invalid; I suspect that's a bug) it would still be confusing. "c" would possibly make sense without causing any confusion, although it would no doubt suggest "currency" to people :)
Jon Skeet
"c" conflicts with the character literal for strings in VB.Net, though even there the grammar is a little different.
Joel Coehoorn
I wouldn't have too much problem with it being different in C# and VB. VB already has different hex syntax for example, IIRC.
Jon Skeet
By the way, I read your book (C# In Depth) and I just want to give you a heads up and let you know that it was outstanding and I did learn a few things.
coson
Many thanks - I'm hard at work on the second edition at the moment :)
Jon Skeet