信息
您所需的主题如下所示。但此主题未包含在此库中。

Decimal.Equals 方法 (Decimal, Decimal)

2013/12/13

返回一个值,该值指示 Decimal 的两个指定实例是否表示同一个值。

Namespace:  System
程序集:  mscorlib(位于 mscorlib.dll 中)

public static bool Equals(
	decimal d1,
	decimal d2
)

参数

d1
类型: System.Decimal
Decimal
d2
类型: System.Decimal
Decimal

返回值

类型: System.Boolean
如果 d1d2 相等,则为 true;否则为 false

下面的代码示例使用静态 Decimal.Equals(Decimal, Decimal) 方法,将几个 Decimal 值同一个参考 Decimal 值进行比较。


// Example of the decimal.Compare and static decimal.Equals methods.
using System;

class Example
{
   const string dataFmt = "{0,-45}{1}";

   // Compare decimal parameters, and display them with the results.
   public static void CompareDecimals(System.Windows.Controls.TextBlock outputBlock, decimal Left, decimal Right,
       string RightText)
   {
      outputBlock.Text += "\n";
      outputBlock.Text += String.Format(dataFmt, "Right: " + RightText, Right) + "\n";
      outputBlock.Text += String.Format(dataFmt, "decimal.Equals( Left, Right )",
          Decimal.Equals(Left, Right)) + "\n";
      outputBlock.Text += String.Format(dataFmt, "decimal.Compare( Left, Right )",
          Decimal.Compare(Left, Right)) + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "This example of the " +
          "decimal.Equals( decimal, decimal ) and \n" +
          "decimal.Compare( decimal, decimal ) methods " +
          "generates the \nfollowing output. It creates several " +
          "different decimal \nvalues and compares them with " +
          "the following reference value.\n" + "\n";

      // Create a reference decimal value.
      decimal Left = new decimal(123.456);

      outputBlock.Text += String.Format(dataFmt, "Left: decimal( 123.456 )",
          Left) + "\n";

      // Create decimal values to compare with the reference.
      CompareDecimals(outputBlock, Left, new decimal(1.2345600E+2),
          "decimal( 1.2345600E+2 )");
      CompareDecimals(outputBlock, Left, 123.4561M, "123.4561M");
      CompareDecimals(outputBlock, Left, 123.4559M, "123.4559M");
      CompareDecimals(outputBlock, Left, 123.456000M, "123.456000M");
      CompareDecimals(outputBlock, Left,
          new decimal(123456000, 0, 0, false, 6),
          "decimal( 123456000, 0, 0, false, 6 )");
   }
}

/*
This example of the decimal.Equals( decimal, decimal ) and
decimal.Compare( decimal, decimal ) methods generates the
following output. It creates several different decimal
values and compares them with the following reference value.

Left: decimal( 123.456 )                     123.456

Right: decimal( 1.2345600E+2 )               123.456
decimal.Equals( Left, Right )                True
decimal.Compare( Left, Right )               0

Right: 123.4561M                             123.4561
decimal.Equals( Left, Right )                False
decimal.Compare( Left, Right )               -1

Right: 123.4559M                             123.4559
decimal.Equals( Left, Right )                False
decimal.Compare( Left, Right )               1

Right: 123.456000M                           123.456000
decimal.Equals( Left, Right )                True
decimal.Compare( Left, Right )               0

Right: decimal( 123456000, 0, 0, false, 6 )  123.456000
decimal.Equals( Left, Right )                True
decimal.Compare( Left, Right )               0
*/


Windows Phone OS

受以下版本支持: 8.0, 7.1, 7.0

Windows Phone

显示: