Blog Stats
  • Posts - 157
  • Articles - 0
  • Comments - 90
  • Trackbacks - 19

 

A few words on C# real literals

decimal discount = 123.5m;

In the above code we set the literal value 123.5 to the variable discount. A literal value is a source code representation of a value. Beacuse it is suffixed with m we know that it is a real literal which are used to write values of types float, double and decimal. The suffix m is called a real-type-suffix. There the literal 123.5m represents a decimal type.

In the above example if we would have omitted the m real-type suffix the conversion would not possible since the literal value 123.5 would represent a double type which we will implicitly try to convert to a decimal type.

For more information concerning real literals take a look at the C# Language Specification (ECMA 334), paragraph 9.4.4.3. 

 


Cross-posted from The .NET Aficionado
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © Gabriel Lozano-Morán