當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C# Int32.MinValue用法及代碼示例


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

參考:



相關用法


注:本文由純淨天空篩選整理自ankita_saini大神的英文原創作品 Int32.MinValue Field in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。