C#中的Single.Equals()方法与示例
C#中的Single.Equals()方法用于返回一个值,该值指示Single的两个实例是否表示相同的值。
语法
public bool Equals (float ob); public override bool Equals (object ob);
两种语法的参数ob是要与此实例进行比较的对象。
示例
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