当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Byte.Equals(Byte)用法及代码示例


此方法用于返回一个值,该值指示此实例和指定的Byte对象是否表示相同的值。

用法:

public bool Equals (byte obj);

此处,obj是要与该实例进行比较的字节对象。


返回值:如果obj等于该实例,则此方法返回true,否则返回false。

以下示例程序旨在说明Byte.Equals(Byte)方法的用法:

示例1:

// C# program to demonstrate 
// Byte.Equals(byte) Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring val1 and val2 
        byte val1, val2; 
  
        // intializing the val1, val2 and val3 
        val1 = 12; 
        val2 = 13; 
  
        // getting compared constant 
        // using CompareTo method 
        bool i = val2.Equals(val1); 
  
        // checking the condition 
        if (i) 
            Console.Write("val2 is equal to val1"); 
  
        else
            Console.Write("val2 is not equal to val1"); 
    } 
}
输出:
val2 is not equal to val1

示例2:

// C# program to demonstrate 
// Byte.Equals(byte) Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // checking the condition 
        // calling check() method 
        check((byte)10, (byte)20); 
        check((byte)30, (byte)20); 
        check((byte)10, (byte)10); 
        check((byte)5, (byte)7); 
        check((byte)40, (byte)50); 
        check((byte)1, (byte)1); 
    } 
  
    // Defining the check method 
    public static void check(byte v1, byte v2) 
    { 
  
        // getting compared constant 
        // using Equals() method 
        bool i = v1.Equals(v2); 
  
        // checking the condition 
        if (i) 
            Console.WriteLine(v1 + " is equal to " + v2); 
  
        else
            Console.WriteLine(v1 + " is not equal to " + v2); 
    } 
}
输出:
10 is not equal to 20
30 is not equal to 20
10 is equal to 10
5 is not equal to 7
40 is not equal to 50
1 is equal to 1

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 C# | Byte.Equals(Byte) Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。