What is the MinusOne field of decimal in C#?

Overview

Decimal.MinusOne is a decimal field in C#. It represents the number negative one (-1).

Syntax

public static readonly decimal MinusOne;
Syntax for Decimal.MinusOne field

Return value

The value returned is minus one (-1).

Code example

// use System
using System;
// create class
class HelloWorld
{
static void Main()
{
// print the field
Console.WriteLine(Decimal.MinusOne);
// create decimal values
decimal decimalNumberOne = Decimal.MinusOne;
decimal decimalNumberTwo = 3.4m + Decimal.MinusOne;
decimal decimalNumberThree = 10.00m / Decimal.MinusOne;
// print values
Console.WriteLine(decimalNumberOne);
Console.WriteLine(decimalNumberTwo);
Console.WriteLine(decimalNumberThree);
}
}

Explanation

  • Line 9: We print the value of the field Decimal.MinusOne.
  • Lines 12-14: We create some decimal variables. We then initialize them using the Decimal.MinusOne field as a value.
  • Lines 17-19: We print the results.

Free Resources