C# Single CompareTo(Single)

Description

Single CompareTo(Single) compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number.

Syntax

Single.CompareTo(Single) has the following syntax.


public int CompareTo(
  float value
)

Parameters

Single.CompareTo(Single) has the following parameters.

  • value - A single-precision floating-point number to compare.

Returns

Single.CompareTo(Single) method returns A signed number indicating the relative values of this instance and value. Return Value Description Less than zero This instance is less than value. -or- This instance is not a number (NaN) and value is a number. Zero This instance is equal to value. -or- Both this instance and value are not a number (NaN), PositiveInfinity, or NegativeInfinity. Greater than zero This instance is greater than value. -or- This instance is a number and value is not a number (NaN).

Example


using System;/* www  .  j  a  v a2  s .com*/

class Sample 
{
    public static void Main() 
    {
        Single   g1 = 6.6f,  g2 = 6.6f;
        Console.WriteLine(g1.CompareTo(g2));
        Console.WriteLine(g1.CompareTo((Object)g2));
    }
}

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