Re: decimal.MaxValue should be a constant

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 06/01/04


Date: Tue, 1 Jun 2004 10:28:21 +0100

Günter Zöchbauer <zoechi@gmx.net> wrote:
> can anyone tell why
>
> [DefaultValue(int.MaxValue)] is valid
>
> but
>
> [DefaultValue(decimal.MaxValue)] produces compiler error:
>
> An attribute argument must be a constant expression, typeof expression or
> array creation expression

It looks like it's a bug in the way decimal.MaxValue is declared.
Rather than a compile-time constant, it's declared to just be static
readonly. I suspect this may make it easier to "get right" in the
class, but it's certainly a bit of a downside for anyone wanting to use
it in the way you do.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages