为了表明此实例是否等于指定的对象或UInt16,代码如下-
using System; public class Demo { public static void Main(){ ushort val1 = 52; ushort val2 = 10; bool res = val1.Equals(val2); Console.WriteLine("Return value (comparison) = "+res); if (res) Console.WriteLine("val1 = val2"); else Console.WriteLine("val1 != val2"); } }
输出结果
这将产生以下输出-
Return value (comparison) = False val1 != val2
现在让我们来看另一个示例-
using System; public class Demo { public static void Main(){ ushort val1 = 100; ushort val2 = 100; bool res = val1.Equals(val2); Console.WriteLine("Return value (comparison) = "+res); if (res) Console.WriteLine("val1 = val2"); else Console.WriteLine("val1 != val2"); } }
输出结果
这将产生以下输出-
Return value (comparison) = True val1 = val2