Single.Equals() Method in C# with Examples



The Single.Equals() method in C# is used to return a value indicating whether two instances of Single represent the same value.

Syntax

public bool Equals (float ob);
public override bool Equals (object ob);

The parameter ob for the both the syntaxes is an object to compare with this instance.

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      float f1 = 15.9f;
      float f2 = 40.2f;
      Console.WriteLine("Value1 = "+f1);
      Console.WriteLine("Value2 = "+f2);  
      Console.WriteLine("Are both the values equal? = "+f1.Equals(f2));
   }
}

Output

Value1 = 15.9
Value2 = 40.2
Are both the values equal? = False

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      float f1 = 10.9f;
      object f2 = 10.9f;
      Console.WriteLine("Value1 = "+f1);
      Console.WriteLine("Value2 = "+f2);
      Console.WriteLine("Are both the values equal? = "+f1.Equals(f2));
   }
}

Output

Value1 = 10.9
Value2 = 10.9
Are both the values equal? = True
Updated on: 2019-12-02T12:11:42+05:30

93 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements