Skip to main content
.NET Framework Class Library
NullableTEquals Method

Indicates whether the current NullableT object is equal to a specified object.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)
Syntax
Public Overrides Function Equals ( _
	other As [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_0_0_0%] _
) As [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_0_0_1%]
public override [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_1_0_0%] Equals(
	[%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_1_0_1%] other
)
public:
virtual [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_2_0_0%] Equals(
	[%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_2_0_1%]^ other
) override
abstract Equals : 
        other:[%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_3_0_0%] -> [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_3_0_1%]  
override Equals : 
        other:[%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_3_0_2%] -> [%$TOPIC/c7b1e4z6_en-us_VS_110_2_0_3_0_3%]

Parameters

other
Type: SystemObject

An object.

Return Value

Type: SystemBoolean
true if the other parameter is equal to the current NullableT object; otherwise, false.
This table describes how equality is defined for the compared values:

Return Value

Description

true

The HasValue property is false, and the other parameter is . That is, two null values are equal by definition.

-or-

The HasValue property is true, and the value returned by the Value property is equal to the other parameter.

false

The HasValue property for the current NullableT structure is true, and the other parameter is .

-or-

The HasValue property for the current NullableT structure is false, and the other parameter is not .

-or-

The HasValue property for the current NullableT structure is true, and the value returned by the Value property is not equal to the other parameter.

Remarks

If the HasValue property of the current NullableT structure is true, equality is determined by passing the other parameter to the Equals method of the underlying value of the current NullableT structure.

Examples

The following code example determines whether an object and a NullableT object are equal to the current NullableT object.

' This code example demonstrates the Nullable(Of T).Equals  
' methods. 

Imports System

Class Sample
    Public Shared Sub Main() 
        Dim nullInt1 As Nullable(Of Integer) = 100 
        Dim nullInt2 As Nullable(Of Integer) = 200
        Dim myObj As Object 

    ' Determine if two nullable of System.Int32 values are equal.  
    ' The nullable objects have different values.
        Console.Write("1) nullInt1 and nullInt2 ")
        If nullInt1.Equals(nullInt2) Then
            Console.Write("are")
        Else
            Console.Write("are not")
        End If
        Console.WriteLine(" equal.")

    ' Determine if a nullable of System.Int32 and an object  
    ' are equal. The object contains the boxed value of the 
    ' nullable object.
        myObj = CType(nullInt1, Object)
        Console.Write("2) nullInt1 and myObj ")
        If nullInt1.Equals(myObj) Then
            Console.Write("are")
        Else
            Console.Write("are not")
        End If
        Console.WriteLine(" equal.")
    End Sub 'Main 
End Class 'Sample

' 
'This code example produces the following results: 
' 
'1) nullInt1 and nullInt2 are not equal. 
'2) nullInt1 and myObj are equal. 
'
// This code example demonstrates the Nullable<T>.Equals  
// methods. 

using System;

class Sample 
{
    public static void Main() 
    {
    int? nullInt1 = 100;
    int? nullInt2 = 200;
    object myObj;

// Determine if two nullable of System.Int32 values are equal. 
// The nullable objects have different values.
    Console.Write("1) nullInt1 and nullInt2 ");
    if (nullInt1.Equals(nullInt2))
        Console.Write("are");
    else
        Console.Write("are not");
    Console.WriteLine(" equal.");

// Determine if a nullable of System.Int32 and an object  
// are equal. The object contains the boxed value of the 
// nullable object.

    myObj = (object)nullInt1;
    Console.Write("2) nullInt1 and myObj ");
    if (nullInt1.Equals(myObj))
        Console.Write("are");
    else
        Console.Write("are not");
    Console.WriteLine(" equal.");
    }
}

/*
This code example produces the following results:

1) nullInt1 and nullInt2 are not equal.
2) nullInt1 and myObj are equal.

*/
Version Information

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1
Platforms

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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