Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
42m is not a constant

Here's a little CLR tidbit I picked up today while writing a [RowTest] with MbUnit.

If you want to specify a decimal value in C#, you add the suffix m or M.  You can read all about it here.  This means you might have something in your code  like this:

decimal myBigMoney = 19.95m;

Well, it turns out that 19.95m is not a constant value, it's actually shorthand that the compiler translates to

decimal myBigMoney = new decimal(19.95);

and "decimal" is an alias of the struct System.Decimal. This means that you can't pass the value 19.95m as an argument into an attribute, like this:


(because attribute arguments must be constants!) Luckily, MbUnit 2.4 will implicitly convert your doubles into decimals for you...

Where credit is due: I discovered this here.

Posted 10-30-2007 3:18 PM by Christopher Bennage
Filed under: ,


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)