What is Decimal.Zero in C#?
Overview
Decimal.Zero is a C# Decimal field that represents the number zero (0).
Syntax
public static readonly decimal Zero;
Syntax For Decimal.Zero field
Parameters
It takes no parameters and is only invoked on the decimal.
Return value
The value returned is a zero (0).
Code example
// use Systemusing System;// create classclass DecimalZero{// main methodstatic void Main(){// print the fieldConsole.WriteLine(Decimal.Zero);// perform arithmetic operationsdecimal d1 = 3.44m + Decimal.Zero;decimal d2 = Decimal.Zero + 4.23m;decimal d3 = Decimal.Zero - Decimal.Zero;// print valuesConsole.WriteLine(d1);Console.WriteLine(d2);Console.WriteLine(d3);}}
Explanation
- Line 10: We print the value of the
Decimal.Zerofield. - Line 13-15: We perform some arithmetic operations using the
Decimal.Zerofield. We then store the results on some decimal variablesd1,d2, andd3. - Line 17: We print the values of the results.