次の方法で共有


Decimal.One Field

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents the number one (1).

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<DecimalConstantAttribute(, , , , )> _
Public Shared ReadOnly One As Decimal
[DecimalConstantAttribute(, , , , )]
public static readonly decimal One

Examples

The following code example illustrates the use of the One field.

' Example of the Decimal fields.
Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      Const numberFmt As String = "{0,-25}{1,45:N0}"
      Const exprFmt As String = "{0,-55}{1,15}"

      outputBlock.Text &= _
          "This example of the fields of the Decimal structure" & _
          vbCrLf & "generates the following output." & vbCrLf + vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "Field or Expression", "Value") & vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "-------------------", "-----") & vbCrLf

      ' Display the values of the Decimal fields.
      outputBlock.Text &= String.Format(numberFmt, "Decimal.MaxValue", _
          Decimal.MaxValue) + vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "Decimal.MinValue", _
          Decimal.MinValue) + vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "Decimal.MinusOne", _
          Decimal.MinusOne) + vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "Decimal.One", _
          Decimal.One) + vbCrLf
      outputBlock.Text &= String.Format(numberFmt, "Decimal.Zero", _
          Decimal.Zero) + vbCrLf
      outputBlock.Text &= vbCrLf

      ' Display the values of expressions of the Decimal fields.
      outputBlock.Text &= String.Format(exprFmt, _
          "( Decimal.MinusOne + Decimal.One ) = Decimal.Zero", _
          (Decimal.MinusOne + Decimal.One) = Decimal.Zero) + vbCrLf
      outputBlock.Text &= String.Format(exprFmt, _
          "Decimal.MaxValue + Decimal.MinValue", _
          Decimal.MaxValue + Decimal.MinValue) + vbCrLf
      outputBlock.Text &= String.Format(exprFmt, _
          "Decimal.MinValue / Decimal.MaxValue", _
          Decimal.MinValue / Decimal.MaxValue) + vbCrLf
      outputBlock.Text &= String.Format("{0,-40}{1,30}", _
          "100000000000000D / Decimal.MaxValue", _
          100000000000000D / Decimal.MaxValue) + vbCrLf
   End Sub
End Module
' This example generates the following output.
' 
' Field or Expression                                              Value
' -------------------                                              -----
' Decimal.MaxValue                79,228,162,514,264,337,593,543,950,335
' Decimal.MinValue               -79,228,162,514,264,337,593,543,950,335
' Decimal.MinusOne                                                    -1
' Decimal.One                                                          1
' Decimal.Zero                                                         0
' 
' ( Decimal.MinusOne + Decimal.One ) = Decimal.Zero                 True
' Decimal.MaxValue + Decimal.MinValue                                  0
' Decimal.MinValue / Decimal.MaxValue                                 -1
' 100000000000000D / Decimal.MaxValue     0.0000000000000012621774483536
// Example of the Decimal fields.
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      const string numberFmt = "{0,-25}{1,45:N0}";
      const string exprFmt = "{0,-55}{1,15}";

      outputBlock.Text += 
          "This example of the fields of the Decimal structure " +
          "\ngenerates the following output.\n" + "\n";
      outputBlock.Text += String.Format(numberFmt, "Field or Expression", "Value") + "\n";
      outputBlock.Text += String.Format(numberFmt, "-------------------", "-----") + "\n";

      // Display the values of the Decimal fields.
      outputBlock.Text += String.Format(numberFmt, "Decimal.MaxValue",
          Decimal.MaxValue) + "\n";
      outputBlock.Text += String.Format(numberFmt, "Decimal.MinValue",
          Decimal.MinValue) + "\n";
      outputBlock.Text += String.Format(numberFmt, "Decimal.MinusOne",
          Decimal.MinusOne) + "\n";
      outputBlock.Text += String.Format(numberFmt, "Decimal.One", Decimal.One) + "\n";
      outputBlock.Text += String.Format(numberFmt, "Decimal.Zero", Decimal.Zero) + "\n";
      outputBlock.Text += "\n";

      // Display the values of expressions of the Decimal fields.
      outputBlock.Text += String.Format(exprFmt,
          "( Decimal.MinusOne + Decimal.One ) == Decimal.Zero",
          (Decimal.MinusOne + Decimal.One) == Decimal.Zero) + "\n";
      outputBlock.Text += String.Format(exprFmt,
          "Decimal.MaxValue + Decimal.MinValue",
          Decimal.MaxValue + Decimal.MinValue) + "\n";
      outputBlock.Text += String.Format(exprFmt,
          "Decimal.MinValue / Decimal.MaxValue",
          Decimal.MinValue / Decimal.MaxValue) + "\n";
      outputBlock.Text += String.Format("{0,-40}{1,30}",
          "100000000000000M / Decimal.MaxValue",
          100000000000000M / Decimal.MaxValue) + "\n";
   }
}

/*
This example of the fields of the Decimal structure
generates the following output.

Field or Expression                                              Value
-------------------                                              -----
Decimal.MaxValue                79,228,162,514,264,337,593,543,950,335
Decimal.MinValue               -79,228,162,514,264,337,593,543,950,335
Decimal.MinusOne                                                    -1
Decimal.One                                                          1
Decimal.Zero                                                         0

( Decimal.MinusOne + Decimal.One ) == Decimal.Zero                True
Decimal.MaxValue + Decimal.MinValue                                  0
Decimal.MinValue / Decimal.MaxValue                                 -1
100000000000000M / Decimal.MaxValue     0.0000000000000012621774483536
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.