This documentation is archived and is not being maintained.

Decimal.Equality Operator

Returns a value indicating whether two instances of Decimal are equal.

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

'Declaration
Public Shared Operator = ( _
	d1 As Decimal, _
	d2 As Decimal _
) As Boolean

Parameters

d1
Type: System.Decimal
The first value to compare.
d2
Type: System.Decimal
The second value to compare.

Return Value

Type: System.Boolean
true if d1 and d2 are equal; otherwise, false.

The following code example compares several Decimal values to a reference Decimal value using the Equality operator.


' Example of the Decimal relational operators.
Imports System
Imports Microsoft.VisualBasic

Module DecRelationalOpsDemo

    Const dataFmt As String = "{0,-47}{1}"

    ' Compare Decimal parameters, and display them with the results.
    Sub CompareDecimals( Left As Decimal, Right As Decimal, _
        RightText As String )

        Console.WriteLine( )
        Console.WriteLine( dataFmt, "Right: " & RightText, Right )

        ' The op_Equality, op_GreaterThan, op_GreaterThanOrEqual, 
        ' op_Inequality, op_LessThan, and op_LessThanOrEqual operators 
        ' must be explicitly coded in Visual Basic. If binary =, >, 
        ' >=, <>, <, or <= are used, the Compare method is called.
        Console.WriteLine( dataFmt, _
            "Decimal.op_Equality( Left, Right )", _
            Decimal.op_Equality( Left, Right ) )
        Console.WriteLine( dataFmt, _
            "Decimal.op_GreaterThan( Left, Right )", _
            Decimal.op_GreaterThan( Left, Right ) )
        Console.WriteLine( dataFmt, _
            "Decimal.op_GreaterThanOrEqual( Left, Right )", _
            Decimal.op_GreaterThanOrEqual( Left, Right ) )
        Console.WriteLine( dataFmt, _
            "Decimal.op_Inequality( Left, Right )", _
            Decimal.op_Inequality( Left, Right ) )
        Console.WriteLine( dataFmt, _
            "Decimal.op_LessThan( Left, Right )", _
            Decimal.op_LessThan( Left, Right ) )
        Console.WriteLine( dataFmt, _
            "Decimal.op_LessThanOrEqual( Left, Right )", _
            Decimal.op_LessThanOrEqual( Left, Right ) )
    End Sub 

    Sub Main( )
        Dim Left As New Decimal( 123.456 )

        Console.WriteLine( _
            "This example of the Decimal relational operators " & _
            "generates the " & vbCrLf & "following output. It " & _
            "creates several different Decimal values " & vbCrLf & _
            "and compares them with the following reference " & _
            "value." & vbCrLf )
        Console.WriteLine( dataFmt, "Left: Decimal( 123.456 )", Left )

        ' Create objects to compare with a 2-hour Decimal.
        CompareDecimals( Left, New Decimal( 1.23456E+2 ), _
            "Decimal( 1.23456E+2 )" )
        CompareDecimals( Left, New Decimal( 123.4567 ), _
            "Decimal( 123.4567 )" )
        CompareDecimals( Left, New Decimal( 123.4553 ), _
            "Decimal( 123.4553 )" )
        CompareDecimals( Left, New Decimal( 123456000, 0, 0, False, 6 ), _
            "Decimal( 123456000, 0, 0, False, 6 )" )
    End Sub 
End Module 

' This example of the Decimal relational operators 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.23456E+2 )                   123.456
' Decimal.op_Equality( Left, Right )             True
' Decimal.op_GreaterThan( Left, Right )          False
' Decimal.op_GreaterThanOrEqual( Left, Right )   True
' Decimal.op_Inequality( Left, Right )           False
' Decimal.op_LessThan( Left, Right )             False
' Decimal.op_LessThanOrEqual( Left, Right )      True
' 
' Right: Decimal( 123.4567 )                     123.4567
' Decimal.op_Equality( Left, Right )             False
' Decimal.op_GreaterThan( Left, Right )          False
' Decimal.op_GreaterThanOrEqual( Left, Right )   False
' Decimal.op_Inequality( Left, Right )           True
' Decimal.op_LessThan( Left, Right )             True
' Decimal.op_LessThanOrEqual( Left, Right )      True
' 
' Right: Decimal( 123.4553 )                     123.4553
' Decimal.op_Equality( Left, Right )             False
' Decimal.op_GreaterThan( Left, Right )          True
' Decimal.op_GreaterThanOrEqual( Left, Right )   True
' Decimal.op_Inequality( Left, Right )           True
' Decimal.op_LessThan( Left, Right )             False
' Decimal.op_LessThanOrEqual( Left, Right )      False
' 
' Right: Decimal( 123456000, 0, 0, False, 6 )    123.456000
' Decimal.op_Equality( Left, Right )             True
' Decimal.op_GreaterThan( Left, Right )          False
' Decimal.op_GreaterThanOrEqual( Left, Right )   True
' Decimal.op_Inequality( Left, Right )           False
' Decimal.op_LessThan( Left, Right )             False
' Decimal.op_LessThanOrEqual( Left, Right )      True


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: