What is Decimal.MinValue in C#?
Overview
Decimal.MinValue is a field in C# that represents the smallest possible value of decimal. It is a constant field and read-only, which means that it cannot be modified.
Syntax
public static readonly decimal MinValue;
Syntax to get minimum value of decimal
Return value
This field returns the value -79,228,162,514,264,337,593,543,950,335.
Code example
// use Systemusing System;// create classclass DecimalMinValue{// main methodstatic void Main(){// print the field valueConsole.WriteLine(Decimal.MinValue);}}
Explanation
- Line 11: We print the value of the
Decimal.MinValuefield to the console.
If there is a decimal value that is less than the Decimal.MinValue, the field will throw an error, as this is the minimum value a decimal can be.
Code example
// use Systemusing System;// create classclass DecimalMinValue{static void Main(){// add to another// decimal valuedecimal newDecimalNumber = -1.0m + Decimal.MinValue;// print resultConsole.WriteLine(newDecimalNumber);}}
Explanation
- Line 10: We create a decimal variable and initialize it with the sum of
-1.0andDecimal.MinValue. This will throw an error because no decimal value is supposed to be less than theDecimal.MinValuefield.