'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."
Sometimes this can come in handy to let the compiler know which overloaded method you want to call:
void test(decimal d)
{
}
void test(int i)
{
}
test(System.Decimal.Zero);
If you just use "test(0)", then the second overload will always be called.
(note: there are also other ways to do this).
mcp111
Participant
835 Points
272 Posts
Why use System.Decimal.Zero?
Dec 17, 2009 07:40 PM|LINK
Why not just 0
Partha Mandayam
Application Developer
University Hospitals
Consulting Expert at Zintro
www.zintro.com/expert/mcp111
SGWellens
All-Star
126031 Points
10310 Posts
Moderator
Re: Why use System.Decimal.Zero?
Dec 17, 2009 08:45 PM|LINK
From this link: http://stackoverflow.com/questions/745591/what-is-the-purpose-of-decimal-one-decimal-zero-decimal-minusone-in-c
'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."
My blog
David Anton
Contributor
3704 Points
638 Posts
Re: Why use System.Decimal.Zero?
Dec 18, 2009 01:42 PM|LINK
Sometimes this can come in handy to let the compiler know which overloaded method you want to call:
void test(decimal d) { } void test(int i) { } test(System.Decimal.Zero); If you just use "test(0)", then the second overload will always be called. (note: there are also other ways to do this).http://www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter