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 System
using System;
// create class
class DecimalMinValue
{
// main method
static void Main()
{
// print the field value
Console.WriteLine(Decimal.MinValue);
}
}

Explanation

  • Line 11: We print the value of the Decimal.MinValue field 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 System
using System;
// create class
class DecimalMinValue
{
static void Main()
{
// add to another
// decimal value
decimal newDecimalNumber = -1.0m + Decimal.MinValue;
// print result
Console.WriteLine(newDecimalNumber);
}
}

Explanation

  • Line 10: We create a decimal variable and initialize it with the sum of -1.0 and Decimal.MinValue. This will throw an error because no decimal value is supposed to be less than the Decimal.MinValue field.

Free Resources