C# Single Equals(Single)

Description

Single Equals(Single) returns a value indicating whether this instance and a specified Single object represent the same value.

Syntax

Single.Equals(Single) has the following syntax.


public bool Equals(
  float obj
)

Parameters

Single.Equals(Single) has the following parameters.

  • obj - An object to compare with this instance.

Returns

Single.Equals(Single) method returns true if obj is equal to this instance; otherwise, false.

Example

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


/*w w w.j  av a 2 s.  c om*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    float float1 = .33333f;
    float float2 = 1/3;
    // Compare them for equality
    Console.WriteLine(float1.Equals(float2));    // 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