The Single.Equals() method in C# is used to return a value indicating whether two instances of Single represent the same value.
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.
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)); } }
Value1 = 15.9 Value2 = 40.2 Are both the values equal? = False
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)); } }
Value1 = 10.9 Value2 = 10.9 Are both the values equal? = True