Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Nullable<T>.Equals Method

Indicates whether the current Nullable<T> object is equal to a specified object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public override bool Equals(
	Object other
)

Parameters

other
Type: System.Object

An object.

Return Value

Type: System.Boolean
true if the other parameter is equal to the current Nullable<T> 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 null. 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 Nullable<T> structure is true, and the other parameter is null.

-or-

The HasValue property for the current Nullable<T> structure is false, and the other parameter is not null.

-or-

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

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

The following code example determines whether an object and a Nullable<T> object are equal to the current Nullable<T> object.

// 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.

*/

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft. All rights reserved.