Code:
decimal m1; // good
decimal m2 = 100; // better
decimal m3 = 100M; // best
The declaration of m1 allocates a variable m1 without initializing it to anything.
Until you assign it a value, the contents of m1 are indeterminate. But that’s
okay, because C# doesn’t let you use m1 for anything until you assign it a value.
The second declaration creates a variable m2 and initializes it to a value of 100.
What isn’t obvious is that 100 is actually of type int. Thus, C# must convert
the int into a decimal type before performing the initialization. Fortunately,
C# understands what you mean and performs the conversion for you.
The declaration of m3 is the best. This clever declaration initializes m3 with
the decimal constant 100M.
The letter M at the end of the number specifies
that the constant is of type decimal. No conversion is required.[/color green]