📜  C#| Byte.MinValue字段

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

字节结构的MinValue字段用于表示字节数据类型的最小可能值。该字段的值是常数,表示用户无法更改该字段的值。该字段的值为0

句法:

public const byte MinValue = 0;

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

例子:

// C# program to illustrate the
// Byte.MinValue field
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
        // display the Minimum value of Byte struct
        Console.WriteLine("Minimum Value is: " + Byte.MinValue);
  
        // Taking an array of the
        // integers
        int[] num = {12, 45, 1235, 5342};
  
        // taking variable of Byte type
        byte mynum;
  
        foreach(int n in num)
        {
  
            if (n >= Byte.MinValue && n <= Byte.MaxValue)
            {
  
                // using the method of Convert class
                mynum = Convert.ToByte(n);
  
                Console.WriteLine("Conversion is Possible.");
            }
  
            else 
            {
                Console.WriteLine("Not Possible");
            }
        }
    }
}

输出:

Minimum Value is: 0
Conversion is Possible.
Conversion is Possible.
Not Possible
Not Possible

参考:

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