C# Double Equals(Object)

Description

Double Equals(Object) returns a value indicating whether this instance is equal to a specified object.

Syntax

Double.Equals(Object) has the following syntax.


public override bool Equals(
  Object obj
)

Parameters

Double.Equals(Object) has the following parameters.

  • obj - An object to compare with this instance.

Returns

Double.Equals(Object) method returns true if obj is an instance of Double and equals the value of this instance; otherwise, false.

Example

The following example reports that the Double value .3333 and the Double returned by dividing 1 by 3 are unequal.


using System;//from w  ww.ja  v  a2  s  . co  m

public class MainClass{
  public static void Main(String[] argv){  
    // Initialize two doubles with apparently identical values 
    double double1 = .33333;
    object double2 = 1/3;
    // Compare them for equality
    Console.WriteLine(double1.Equals(double2));    // displays false


  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version