📜  C#| Byte.MaxValue字段

📅  最后修改于: 2021-05-29 17:07:05             🧑  作者: Mango

字节结构的MaxValue字段用于表示字节数据类型的最大值。该字段的值是常数,表示用户无法更改该字段的值。该字段的值为255。其十六进制值为0xFF

句法:

public const byte MaxValue = 255;

返回值:该字段始终返回255。

例子:

// C# program to illustrate the
// Byte.MaxValue Field
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
        // display the Maximum
        // value of Byte struct
        Console.WriteLine("Maximum Value is: " + Byte.MaxValue);
  
        // taking a variable
        byte var1 = 255;
  
        if (var1.Equals(Byte.MaxValue)) 
        {
            Console.WriteLine("Equal..!!");
            Console.WriteLine("Type of var1 is: {0}",
                                 var1.GetTypeCode());
        }
  
        else 
        {
            Console.WriteLine("Not equal..!!");
            Console.WriteLine("Type of var1 is: {0}",
                                 var1.GetTypeCode());
        }
    }
}
输出:
Maximum Value is: 255
Equal..!!
Type of var1 is: Byte

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.byte.maxvalue?view=netstandard-2.1