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.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources