📜  C#中的Int32.MinValue字段(带示例)

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

MinValue属性或Int32 Struct的字段用于表示Int32的最小可能值。该字段的值是常数,表示用户无法更改该字段的值。该字段的值是-2,147,483,648 。其十六进制值为0x80000000

句法:

public const int MinValue = -2147483648;

返回值:该字段始终返回-2147483648。

例子:

// C# program to illustrate the
// Int32.MinValue field
using System;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
        // display the Minimum value of Int32 struct
        Console.WriteLine("Minimum Value is: "+
                               Int32.MinValue);
  
        // Taking an array of long i.e Int64 data type
        long []num = {346, 434443, -33445, -442343263647};
  
        // taking variable of Int32 type
        int mynum;
        foreach(long n in num)
        {
  
            if(n >= Int32.MinValue && n <= Int32.MaxValue)
            {
  
                // using the method of Convert class
                mynum = Convert.ToInt32(n);
                Console.WriteLine("Conversion is Possible.");
            }
              
            else
            {
                Console.WriteLine("Not Possible");
            }
        }
          
    }
}

输出:

Minimum Value is: -2147483648
Conversion is Possible.
Conversion is Possible.
Conversion is Possible.
Not Possible

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.int32.minvalue?view=netframework-4.7.2