Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Small clarification. They are actually static readonly values and not constants. That has a distinct difference in .Net because constant values are <em>inlined</em> by the various compilers and hence it's impossible to track their usage in a compiled assembly. Static readonly values however are not copied but instead referenced. This is advantageous to your question because it means the use of them can be analyzed.</p> <p>If you use reflector and dig through the BCL, you'll notice that MinusOne and Zero are only used with in the VB runtime. It exists primarily to serve conversions between Decimal and Boolean values. Why MinusOne is used coincidentally came up on a separate thread just today (<a href="https://stackoverflow.com/questions/745292/convert-boolean-to-integer-in-vb-net/745366#745366">link</a>)</p> <p>Oddly enough, if you look at the Decimal.One value you'll notice it's used nowhere. </p> <p>As to why they are explicitly defined ... I doubt there is a hard and fast reason. There <strong>appears</strong> to be no specific performance and only a bit of a convenience measure that can be attributed to their existence. My <em>guess</em> is that they were added by someone during the development of the BCL for their convenience and just never removed. </p> <p><strong>EDIT</strong></p> <p>Dug into the <code>const</code> issue a bit more after a comment by @Paleta. The C# definition of <code>Decimal.One</code> uses the <code>const</code> modifier however it is emitted as a <code>static readonly</code> at the IL level. The C# compiler uses a couple of tricks to make this value virtually indistinguishable from a <code>const</code> (inlines literals for example). This would show up in a language which recognize this trick (VB.Net recognizes this but F# does not). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload