ฟิลด์ Int32.MaxValue ใน C# ถูกใช้เพื่อแสดงค่าที่น้อยที่สุดที่เป็นไปได้ของ Int32
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
public const int MinValue = -2147483648;
ตัวอย่าง
ให้เราดูตัวอย่างการใช้งานฟิลด์ Int32.MinValue &miuns;
sing System;
public class Demo {
public static void Main(){
int val1 = 23;
int val2 = 0;
Console.WriteLine("Value1 = "+val1);
Console.WriteLine("Value2 = "+val2);
Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
TypeCode type1 = val1.GetTypeCode();
TypeCode type2 = val2.GetTypeCode();
Console.WriteLine("TypeCode for val1 = "+type1);
Console.WriteLine("TypeCode for val2 = "+type2);
Console.WriteLine("Maximum Value = "+ Int32.MaxValue);
Console.WriteLine("Minimum Value = "+ Int32.MinValue);
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Value1 = 23 Value2 = 0 HashCode for value1 = 23 HashCode for value2 = 0 Are they equal? = False TypeCode for val1 = Int32 TypeCode for val2 = Int32 Maximum Value = 2147483647 Minimum Value = -2147483648
ตัวอย่าง
ให้เราดูตัวอย่างอื่นเพื่อใช้ฟิลด์ Int32.MinValue -
using System;
public class Demo {
public static void Main(){
long[]val = {8998, -899898778, 878787878, -20};
int res;
foreach(long a in val){
if(a >= Int32.MinValue && a <= Int32.MaxValue){
res = Convert.ToInt32(a);
Console.WriteLine("Converted: "+res);
}
else{
Console.WriteLine("Not Possible");
}
}
}
} ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
Converted: 8998 Converted: -899898778 Converted: 878787878 Converted: -20